updated bash and python script
This commit is contained in:
parent
60f76d2c13
commit
3ae62a18e7
@ -5,27 +5,35 @@ error_exit() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
source ../.apikey || error_exit "Cannot find apikey"
|
||||
#source ../.apikey || error_exit "Cannot find apikey"
|
||||
|
||||
d=`date +%Y%m%d`
|
||||
#mv "missing.mcl" "missing_old.mcl"
|
||||
|
||||
fromdate=$(ls -1 *_latest.mcl |grep -Eo '[[:digit:]]{8}') || error_exit "cannot latest mcl file"
|
||||
fromdate2=$(date -d "$fromdate" +%Y-%m-%d)
|
||||
|
||||
d2=`date +%Y-%m-%d`
|
||||
#fromdate2=$(date -d $fromdate +%Y-%m-%d)
|
||||
|
||||
TEMP=$(echo "update_missing.py" "$fromdate""_latest.mcl" "$d"".mcl" "$api_key" "$fromdate2" "$d2")
|
||||
#d2=`date +%Y-%m-%d`
|
||||
|
||||
/usr/bin/python2 $TEMP
|
||||
#TEMP="${fromdate}"
|
||||
#TEMP+="_latest.mcl "
|
||||
#TEMP+="${d}"
|
||||
#TEMP+=".mcl "
|
||||
#TEMP+="${api_key} "
|
||||
#TEMP+="${fromdate2} "
|
||||
#TEMP+="${d2}"
|
||||
|
||||
#exit
|
||||
|
||||
#mv "$d"".mcl" "$d""_latest.mcl" || error_exit "cannot cp $d to latest"
|
||||
#mv "$fromdate""_latest.mcl" "archive/""$fromdate"".mcl" || error_exit "cannot mv to archive"
|
||||
python2 update_missing.py
|
||||
|
||||
#git add "$d""_latest.mcl" "archive/"
|
||||
#git commit -m "Updated $d"
|
||||
|
||||
#git push origin master
|
||||
mv "$d"".mcl" "$d""_latest.mcl" || error_exit "cannot cp $d to latest"
|
||||
mv "$fromdate""_latest.mcl" "archive/""$fromdate"".mcl" || error_exit "cannot mv to archive"
|
||||
|
||||
git add "$d""_latest.mcl" "archive/" || error_exit "cannot git add"
|
||||
|
||||
git commit -m "Updated $d" || error_exit "cannot git commit"
|
||||
|
||||
git push origin master || error_exit "cannot git push"
|
||||
|
||||
|
40
Update Missing/update_missing.py
Normal file → Executable file
40
Update Missing/update_missing.py
Normal file → Executable file
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/python2
|
||||
|
||||
"""
|
||||
Ver 2.0
|
||||
@ -42,16 +42,34 @@
|
||||
|
||||
import requests
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
from datetime import date,datetime
|
||||
|
||||
if len(sys.argv) < 6 :
|
||||
print ("usage: python update_missing.py <in_file> <out_file> <api_key> <start_date> <end_date>")
|
||||
exit()
|
||||
temp = ""
|
||||
for i in os.listdir(os.getcwd()):
|
||||
if (i.find("_latest") != -1):
|
||||
temp=i
|
||||
old_date = re.search('[0-9]{8}',temp).group()
|
||||
|
||||
in_file = str(sys.argv[1]) # missing.mcl
|
||||
out_file = str(sys.argv[2]) # updated_missing.mcl
|
||||
api_key = str(sys.argv[3]) # ComicVine API key
|
||||
start_date = str(sys.argv[4]) # start date range to search for new issues
|
||||
end_date = str(sys.argv[5]) # end date range to search for new issues
|
||||
in_file = str(temp)
|
||||
out_file = str(date.today().strftime("%Y%m%d")+"_latest.mcl")
|
||||
data=[]
|
||||
with open("../.apikey", "r") as f:
|
||||
data = f.readlines()
|
||||
|
||||
api_key = str(data[0].strip('\n'))
|
||||
start_date = str(datetime.strptime(re.search('[0-9]{8}',temp).group(),"%Y%m%d").strftime("%Y-%m-%d"))
|
||||
end_date = str(date.today().strftime("%Y-%m-%d"))
|
||||
|
||||
|
||||
if len(sys.argv) > 5:
|
||||
print "Using argvs"
|
||||
in_file = str(sys.argv[1]) # missing.mcl
|
||||
out_file = str(sys.argv[2]) # updated_missing.mcl
|
||||
api_key = str(sys.argv[3]) # ComicVine API key
|
||||
start_date = str(sys.argv[4]) # start date range to search for new issues
|
||||
end_date = str(sys.argv[5]) # end date range to search for new issues
|
||||
|
||||
comiclist = open(in_file, "r")
|
||||
issues_number = {}
|
||||
@ -102,7 +120,7 @@ while offset < max:
|
||||
try:
|
||||
request_url = "https://comicvine.gamespot.com/api/issues/?api_key=" + api_key +"&limit=" + str(limit) + "&format=json&offset=" + str(offset) + "&field_list=id,issue_number,volume&filter=date_last_updated:" + start_date + "|" + end_date + "&sort=id"
|
||||
|
||||
'''print request_url'''
|
||||
print request_url
|
||||
r = requests.get(request_url, headers=headers)
|
||||
json_obj = r.json()
|
||||
|
||||
@ -199,4 +217,4 @@ print (str(deleted_comics_cont) + " comics in databased not retrieved in this ro
|
||||
print (str(updated_comics_cont) + " comics updated in database.")
|
||||
print ("Ids with error in server: " + ErrorIds[1:])
|
||||
print (cont)
|
||||
raw_input("Press Enter to continue...")
|
||||
#raw_input("Press Enter to continue...")
|
||||
|
Loading…
Reference in New Issue
Block a user