diff options
author | Anthony Wang | 2021-11-24 21:26:07 -0600 |
---|---|---|
committer | Anthony Wang | 2021-11-24 21:26:07 -0600 |
commit | 1ea2bc4c95f89c9adf0051087de7e120f9a06cee (patch) | |
tree | d7db3d77e5e27d022d9ec531a002def265ee791b | |
parent | 11c4b464b1ac854f0fe649ee55bd2f5132dfe124 (diff) |
Catch find_date exceptions
-rw-r--r-- | Links/DSOs.txt | 2 | ||||
-rwxr-xr-x | mkbinder.py | 46 |
2 files changed, 27 insertions, 21 deletions
diff --git a/Links/DSOs.txt b/Links/DSOs.txt index 31b33a9..963e4ca 100644 --- a/Links/DSOs.txt +++ b/Links/DSOs.txt @@ -76,7 +76,7 @@ https://www.britannica.com/place/Mira-Ceti # ESO 577-24 https://duckduckgo.com/?q=ESO+577-24&iax=images&ia=images https://www.eso.org/public/images/eso1902c/ -#https://www.astrophotolab.com/pr/n1902eo.htm +https://www.astrophotolab.com/pr/n1902eo.htm https://www.universeguide.com/nebula/eso57724 http://simbad.u-strasbg.fr/simbad/sim-id?Ident=ESO+577-24 https://scitechdaily.com/esos-very-large-telescope-captures-a-fleeting-moment-in-time/ diff --git a/mkbinder.py b/mkbinder.py index 4389e64..ff38307 100755 --- a/mkbinder.py +++ b/mkbinder.py @@ -16,11 +16,10 @@ parser.add_argument('--force', '-f', dest = 'force', help = 'force download all args = parser.parse_args() -for filename in os.listdir("Links"): - if not filename.endswith(".txt"): continue - if filename == "requirements.txt": continue +for filename in os.listdir('Links'): + if not filename.endswith('.txt'): continue - print("Examining: " + filename) + print('Examining: ' + filename) try: os.mkdir(filename[:-4]) @@ -28,34 +27,41 @@ for filename in os.listdir("Links"): pass try: - dates = pickle.load(open(os.path.join("Links", filename[:-4] + ".pickle"), 'rb')) + dates = pickle.load(open(os.path.join('Links', filename[:-4] + '.pickle'), 'rb')) except: dates = {} - file = open(os.path.join("Links", filename), "r") + file = open(os.path.join('Links', filename), 'r') links = file.readlines() + section = '' for link in links: - if link[0] == "#" or link[0] == "\n": continue + if link[0:2] == '# ': + section = link[2:] + if link[0] == '#' or link[0] == '\n': + continue - new_date_str = find_date(link[:-1]) + try: + new_date_str = find_date(link[:-1]) + except: + pass if new_date_str == None: - new_date = date.fromisoformat("9999-01-01") + new_date = date.fromisoformat('9999-01-01') else: new_date = date.fromisoformat(new_date_str) try: old_date = dates[link[:-1]] except: - old_date = date.fromisoformat("1970-01-01") - + old_date = date.fromisoformat('1970-01-01') + # Time to print! if new_date > old_date or args.force: - print("Downloading: " + link[:-1]) - print("Edit date: " + str(new_date)) + print('Downloading: ' + link[:-1]) + print('Edit date: ' + str(new_date)) - name = os.path.join(filename[:-4], re.sub(r'(?u)[^-\w.]', '', link[5:]) + ".pdf") - # name = re.sub(r'(?u)[^-\w.]', '', link[5:]) + ".pdf" + name = os.path.join(filename[:-4], section + ' - ' + re.sub(r'(?u)[^-\w.]', '', link[5:]) + '.pdf') + # name = re.sub(r'(?u)[^-\w.]', '', link[5:]) + '.pdf' # print(name) try: # weasyprint seems faster? @@ -66,13 +72,13 @@ for filename in os.listdir("Links"): pdf = weasyprint.HTML(link).write_pdf() open(name, 'wb').write(pdf) except: # Maybe should handle errors a little bit better? - print("Error when printing") + print('Error when printing') pass - - if new_date != date.fromisoformat("9999-01-01"): + # Update date + if new_date != date.fromisoformat('9999-01-01'): dates[link[:-1]] = new_date - - pickle.dump(dates, open(os.path.join("Links", filename[:-4] + ".pickle"), 'wb')) + # Dump dates to a pickle + pickle.dump(dates, open(os.path.join('Links', filename[:-4] + '.pickle'), 'wb')) |