Fixed regression caused by update of schedule library, added try catch around the settings loading code

This commit is contained in:
Frisk 2019-02-12 14:59:49 +01:00
parent 4c8ce6914c
commit 9d3e80b8da
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C

View file

@ -26,10 +26,15 @@ from collections import defaultdict, Counter
from urllib.parse import quote_plus from urllib.parse import quote_plus
from html.parser import HTMLParser from html.parser import HTMLParser
with open("settings.json") as sfile: try:
settings = json.load(sfile) with open("settings.json") as sfile:
if settings["limitrefetch"] < settings["limit"] and settings["limitrefetch"] != -1: settings = json.load(sfile)
settings["limitrefetch"] = settings["limit"] if settings["limitrefetch"] < settings["limit"] and settings["limitrefetch"] != -1:
settings["limitrefetch"] = settings["limit"]
except FileNotFoundError:
logging.critical("No config file could be found. Please make sure settings.json is in the directory.")
sys.exit(1)
logged_in = False logged_in = False
logging.basicConfig(level=settings["verbose_level"]) logging.basicConfig(level=settings["verbose_level"])
if settings["limitrefetch"] != -1 and os.path.exists("lastchange.txt") == False: if settings["limitrefetch"] != -1 and os.path.exists("lastchange.txt") == False:
@ -1128,8 +1133,15 @@ if 1 == 2:
_("autoreview"), _("autopatrol"), _("wiki_guardian")) _("autoreview"), _("autopatrol"), _("wiki_guardian"))
if settings["overview"]: if settings["overview"]:
schedule.every().day.at("{}:{}".format(time.strptime(settings["overview_time"], '%H:%M').tm_hour, try:
time.strptime(settings["overview_time"], '%H:%M').tm_min)).do(day_overview) overview_time=time.strptime(settings["overview_time"], '%H:%M')
schedule.every().day.at("{}:{}".format(str(overview_time.tm_hour).zfill(2),
str(overview_time.tm_min).zfill(2))).do(day_overview)
del overview_time
except schedule.ScheduleValueError:
logging.error("Invalid time format! Currently: {}:{}".format(time.strptime(settings["overview_time"], '%H:%M').tm_hour, time.strptime(settings["overview_time"], '%H:%M').tm_min))
except ValueError:
logging.error("Invalid time format! Currentely: {}. Note: It needs to be in HH:MM format.".format(settings["overview_time"]))
schedule.every().day.at("00:00").do(recent_changes.clear_cache) schedule.every().day.at("00:00").do(recent_changes.clear_cache)
while 1: while 1: