add in temp files

This commit is contained in:
samerbam 2023-06-11 18:13:07 -04:00
parent 973dbfff4a
commit a6a343fde4

View File

@ -7,7 +7,7 @@ from optparse import OptionParser
import re import re
from configparser import ConfigParser from configparser import ConfigParser
from tempfile import mkdtemp from tempfile import mkdtemp
from shutil import rmtree, copyfile from shutil import rmtree, copyfile, copy2
import socket import socket
from time import strftime, localtime from time import strftime, localtime
import os import os
@ -124,9 +124,10 @@ def check_regexes(output):
def downloader(args): def downloader(args):
url, inout_file, path, live = args url, inout_file, path, live = args
# loc = mkdtemp() loc = mkdtemp()
file_backup = '/config/downloads'
# loc = '/config/downloads'
# loc = '/config/downloads' # loc = '/config/downloads'
loc = '/config/downloads'
if not exists(loc): if not exists(loc):
makedirs(loc) makedirs(loc)
copyfile("/config/personal.ini", "{}/personal.ini".format(loc)) copyfile("/config/personal.ini", "{}/personal.ini".format(loc))
@ -213,6 +214,8 @@ def downloader(args):
'WARNING', 'WARNING',
live) live)
output += log("Added /Story-file to library with id 0", 'GREEN', live) output += log("Added /Story-file to library with id 0", 'GREEN', live)
# copy2(cur, f"/config/downloads/{get_files(loc, '.epub', False)[0]}")
copy2(cur, f"{file_backup}/{get_files(loc, '.epub', False)[0]}")
remove(cur) remove(cur)
else: else:
res = check_output( res = check_output(
@ -221,6 +224,7 @@ def downloader(args):
check_regexes(res) check_regexes(res)
cur = get_files(loc, '.epub', True)[0] cur = get_files(loc, '.epub', True)[0]
name = get_files(loc, '.epub', False)[0] name = get_files(loc, '.epub', False)[0]
copy2(cur, f"{file_backup}/{name}")
rename(cur, name) rename(cur, name)
output += log( output += log(
"Downloaded story {} to {}".format( "Downloaded story {} to {}".format(
@ -230,15 +234,15 @@ def downloader(args):
live) live)
if not live: if not live:
print(output.strip()) print(output.strip())
# rmtree(loc) rmtree(loc)
except Exception as e: except Exception as e:
output += log("Exception: {}".format(e), 'FAIL', live) output += log("Exception: {}".format(e), 'FAIL', live)
if not live: if not live:
print(output.strip()) print(output.strip())
# try: try:
# rmtree(loc) rmtree(loc)
# except BaseException: except BaseException:
# pass pass
with open(inout_file, "a") as fp: with open(inout_file, "a") as fp:
fp.write("{}\n".format(url)) fp.write("{}\n".format(url))