updated bash and python script

This commit is contained in:
Frederik Baerentsen 2022-07-15 10:43:24 +02:00
parent 24cb19ba91
commit e1d4d2e6ee
3 changed files with 26 additions and 14 deletions

View File

@ -23,3 +23,7 @@ py: 882746 comics in databased not retrieved in this round.
py: 0 comics updated in database. py: 0 comics updated in database.
py: Ids with error in server: py: Ids with error in server:
py: 0 py: 0
sh: Moving old file to archive
sh: git add
sh: git rm
sh: Error: cannot git rm

View File

@ -2,8 +2,11 @@
d=`date +%Y%m%d` d=`date +%Y%m%d`
prj_root=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$prj_root"
log2file() { log2file() {
echo "sh: $1" >> "log/$d.log" echo "sh: $1" >> "$prj_root/log/$d.log"
} }
error_exit() { error_exit() {
@ -11,22 +14,25 @@ error_exit() {
exit 1 exit 1
} }
touch "log/$d.log" touch "$prj_root/log/$d.log"
echo "log: $d" >> "log/$d.log" echo "log: $d" >> "$prj_root/log/$d.log"
log2file "Starting update.sh" log2file "Starting update.sh"
fromdate=$(ls -1 *_latest.mcl |grep -Eo '[[:digit:]]{8}') || error_exit "cannot latest mcl file" fromdate=$(ls -1 *_latest.mcl |grep -Eo '[[:digit:]]{8}') || error_exit "cannot latest mcl file"
echo $fromdate
python2 update_missing.py python2 update_missing.py
log2file "Moving old file to archive" log2file "Moving old file to archive"
mv "$fromdate""_latest.mcl" "archive/""$fromdate"".mcl" || error_exit "cannot mv to archive" mv "$prj_root/$fromdate""_latest.mcl" "$prj_root/archive/""$fromdate"".mcl" || error_exit "cannot mv to archive"
log2file "git add" log2file "git add"
git add "$d""_latest.mcl" "archive/" "log/" >> "log/$d.log" || error_exit "cannot git add" git add "$d""_latest.mcl" "Deleted_Comics.txt" "archive/" "log/" >> "log/$d.log" || error_exit "cannot git add"
log2file "git rm" #log2file "git rm"
git rm "$fromdate""_latest.mcl" >> "log/$d.log" || error_exit "cannot git rm" #git rm "$fromdate""_latest.mcl" >> "log/$d.log" || error_exit "cannot git rm"
log2file "git commit" log2file "git commit"
git commit -m "Updated $d" >> "log/$d.log" || error_exit "cannot git commit" git commit -m "Updated $d" >> "log/$d.log" || error_exit "cannot git commit"

View File

@ -46,16 +46,18 @@ import os
import re import re
from datetime import date,datetime from datetime import date,datetime
ROOT_DIR = os.path.join(os.path.realpath(os.path.join(os.path.dirname(__file__), '..')), 'Update Missing/')
temp = "" temp = ""
for i in os.listdir(os.getcwd()): for i in os.listdir(ROOT_DIR):
if (i.find("_latest") != -1): if (i.find("_latest") != -1):
temp=i temp=i
old_date = re.search('[0-9]{8}',temp).group() old_date = re.search('[0-9]{8}',temp).group()
in_file = str(temp) in_file = str(ROOT_DIR)+str(temp)
out_file = str(date.today().strftime("%Y%m%d")+"_latest.mcl") out_file = str(ROOT_DIR)+str(date.today().strftime("%Y%m%d")+"_latest.mcl")
data=[] data=[]
with open("../.apikey", "r") as f: with open(ROOT_DIR+"/.apikey", "r") as f:
data = f.readlines() data = f.readlines()
api_key = str(data[0].strip('\n')) api_key = str(data[0].strip('\n'))
@ -63,7 +65,7 @@ start_date = str(datetime.strptime(re.search('[0-9]{8}',temp).group(),"%Y%m%d").
end_date = str(date.today().strftime("%Y-%m-%d")) end_date = str(date.today().strftime("%Y-%m-%d"))
today_date = str(date.today().strftime("%Y%m%d")) today_date = str(date.today().strftime("%Y%m%d"))
f1=open('log/'+today_date+'.log', 'a') f1=open(ROOT_DIR+'log/'+today_date+'.log', 'a')
if len(sys.argv) > 5: if len(sys.argv) > 5:
print "Using argvs" print "Using argvs"
@ -78,7 +80,7 @@ issues_number = {}
issues_volume = {} issues_volume = {}
skip_header = True skip_header = True
cont = 0 cont = 0
exit
print >>f1, "py: Reading in current database" print >>f1, "py: Reading in current database"
for line in comiclist: for line in comiclist:
@ -191,7 +193,7 @@ for issue_id in issues_number.keys():
print >>f1, "py: Writing missings to file" print >>f1, "py: Writing missings to file"
deleted_file = open("Deleted_Comics.txt", "wb") deleted_file = open(ROOT_DIR+"Deleted_Comics.txt", "wb")
for issue_id in non_retrieved_comics.keys(): for issue_id in non_retrieved_comics.keys():
deleted_file.write(str(issue_id)+"\n") deleted_file.write(str(issue_id)+"\n")