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