From 6aeb1be35db5104516f4e706ab558a70cbad0232 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Wed, 5 Oct 2022 16:31:47 +0200 Subject: [PATCH] updated to python3 --- Update Missing/update_missing.py | 54 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/Update Missing/update_missing.py b/Update Missing/update_missing.py index 0dde506..7bb8780 100755 --- a/Update Missing/update_missing.py +++ b/Update Missing/update_missing.py @@ -68,7 +68,7 @@ today_date = str(date.today().strftime("%Y%m%d")) f1=open(ROOT_DIR+'log/'+today_date+'.log', 'a') if len(sys.argv) > 5: - print "Using argvs" + 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 @@ -81,14 +81,14 @@ issues_volume = {} skip_header = True cont = 0 exit -print >>f1, "py: Reading in current database" +print("py: Reading in current database") for line in comiclist: if skip_header: skip_header = False continue - line_split = unicode(line, encoding='utf-8').replace("\n","").split(";") + line_split = line.replace("\n","").split(";") volume_id = int(line_split[0]) if (line_split[1][0] == '"') and (line_split[1][len(line_split[1])] == '"'): @@ -98,14 +98,16 @@ for line in comiclist: num_split = line_split[2].split(",") for i in range(0,len(issue_split)): - if issues_number.has_key(int(issue_split[i])): + #if issues_number.has_key(int(issue_split[i])): + #if int(issue_split[i]) in issue_number: + if issues_number.__contains__(int(issue_split[i])): cont += 1 issues_number[int(issue_split[i])] = num_split[i] issues_volume[int(issue_split[i])] = volume_id comiclist.close() -print >>f1, "py: Querying ComicVine for new issues" +print("py: Querying ComicVine for new issues") headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'} new_comics_cont = 0 old_comics_cont = 0 @@ -131,14 +133,14 @@ while offset < max: max = json_obj['number_of_total_results'] - print >>f1, "py:" + str(min(offset,max)) + "/" + str(max) + " Since " + start_date + print("py:" + str(min(offset,max)) + "/" + str(max) + " Since " + start_date) for i in json_obj['results']: volume_id = i['volume']['id'] issue_id = i['id'] - num = unicode(i['issue_number']).replace(",",".&@1").replace(";",".&@2").replace("\n","").replace("\r","") + num = i['issue_number'].replace(",",".&@1").replace(";",".&@2").replace("\n","").replace("\r","") - if not issues_number.has_key(issue_id): + if not issues_number.__contains__(issue_id): new_comics_cont += 1 issues_number[issue_id] = num issues_volume[issue_id] = volume_id @@ -155,10 +157,10 @@ while offset < max: FindingError = False if skip == 1: - print >>f1, "py: Comic with error found, id= " + str(issue_id+1) + print("py: Comic with error found, id= " + str(issue_id+1)) ErrorIds += ";"+ str(issue_id+1) comic_skip_cont += 1 - print >>f1, "py: Continue loading comics now..." + print("py: Continue loading comics now...") FindingError = True skip = 0 @@ -167,18 +169,18 @@ while offset < max: except: if retry < 4 and not FindingError: - print >>f1, "py: Error. Trying Again..." + print("py: Error. Trying Again...") retry += 1 else: if not FindingError: - print >>f1, "py: Finding Error in comic list: " + str(100-limit) + "%" + print("py: Finding Error in comic list: " + str(100-limit) + "%") skip = 1 limit -= 1 if limit == 0 or FindingError: - print >>f1, "py: Comic with error found, id= " + str(issue_id+offset) + print("py: Comic with error found, id= " + str(issue_id+offset)) FindingError = True limit = 1 offset += 1 @@ -187,39 +189,39 @@ while offset < max: comics = {} for issue_id in issues_number.keys(): - if not comics.has_key(issues_volume[issue_id]): + if not comics.__contains__(issues_volume[issue_id]): comics[issues_volume[issue_id]] = {} comics[issues_volume[issue_id]][issue_id]=issues_number[issue_id] -print >>f1, "py: Writing missings to file" +print("py: Writing missings to file") deleted_file = open(ROOT_DIR+"Deleted_Comics.txt", "wb") for issue_id in non_retrieved_comics.keys(): - deleted_file.write(str(issue_id)+"\n") + deleted_file.write((str(issue_id)+"\n").encode()) deleted_comics_cont += 1 deleted_file.close() -print >>f1, "py: Writing database to file" +print("py: Writing database to file") outfile = open(out_file,"wb") -outfile.write("Missing;" + end_date + "\n") +outfile.write(("Missing;" + end_date + "\n").encode()) -for volume_id in sorted(comics.iterkeys()): +for volume_id in sorted(comics): issues = "" nums = "" - for issue_id in sorted(comics[volume_id].iterkeys()): + for issue_id in sorted(comics[volume_id]): issues += str(issue_id) + "," nums += comics[volume_id][issue_id] + "," issues = issues[:-1] - outfile.write(str(volume_id) + ";" + issues + ";" + nums.encode('utf-8','ignore') + "\n") + outfile.write((str(volume_id) + ";" + issues + ";" + nums + "\n").encode()) outfile.close() -print >>f1, "py: Done! " + str(new_comics_cont) + " comics added to database! (" + str(comic_skip_cont)+ " skipped and " + str(old_comics_cont) + " comics already in database)" -print >>f1, "py: " + str(deleted_comics_cont) + " comics in databased not retrieved in this round." -print >>f1, "py: " + str(updated_comics_cont) + " comics updated in database." -print >>f1, "py: Ids with error in server: " + ErrorIds[1:] -print >>f1, "py: " + str(cont) +print("py: Done! " + str(new_comics_cont) + " comics added to database! (" + str(comic_skip_cont)+ " skipped and " + str(old_comics_cont) + " comics already in database)") +print("py: " + str(deleted_comics_cont) + " comics in databased not retrieved in this round.") +print("py: " + str(updated_comics_cont) + " comics updated in database.") +print("py: Ids with error in server: " + ErrorIds[1:]) +print("py: " + str(cont)) #raw_input("Press Enter to continue...")