Hotfix, and a few other small changes

This commit is contained in:
Frisk 2018-12-02 11:46:11 +01:00
parent a2770c4ad2
commit c085164050
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C

View file

@ -35,7 +35,7 @@ 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:
with open("lastchange.txt", 'w') as sfile: with open("lastchange.txt", 'w') as sfile:
sfile.write("99999999999") sfile.write("99999999999")
logging.info("Current settings: {settings}".format(settings=settings)) logging.debug("Current settings: {settings}".format(settings=settings))
lang = gettext.translation('rcgcdw', localedir='locale', languages=[settings["lang"]]) lang = gettext.translation('rcgcdw', localedir='locale', languages=[settings["lang"]])
lang.install() lang.install()
ngettext = lang.ngettext ngettext = lang.ngettext
@ -72,6 +72,7 @@ class LinkParser(HTMLParser):
def handle_endtag(self, tag): def handle_endtag(self, tag):
logging.debug(self.new_string) logging.debug(self.new_string)
LinkParser = LinkParser() LinkParser = LinkParser()
@ -97,9 +98,12 @@ def safe_read(request, *keys):
def send_to_discord_webhook(data): def send_to_discord_webhook(data):
header = settings["header"]
if "content" not in data:
header['Content-Type'] = 'application/json'
try: try:
result = requests.post(settings["webhookURL"], data=data, result = requests.post(settings["webhookURL"], data=data,
headers={**{'Content-Type': 'application/json'}, **settings["header"]}, timeout=10) headers=header, timeout=10)
except requests.exceptions.Timeout: except requests.exceptions.Timeout:
logging.warning("Timeouted while sending data to the webhook.") logging.warning("Timeouted while sending data to the webhook.")
return 3 return 3
@ -962,19 +966,22 @@ class recent_changes_class(object):
logging.debug( logging.debug(
"There were too many new events, but the limit was high enough we don't care anymore about fetching them all.") "There were too many new events, but the limit was high enough we don't care anymore about fetching them all.")
if change["type"] == "categorize": if change["type"] == "categorize":
cat_title = change["title"].split(':', 1)[1] if "commenthidden" not in change:
# I so much hate this, blame Markus for making me do this cat_title = change["title"].split(':', 1)[1]
if change["revid"] not in categorize_events: # I so much hate this, blame Markus for making me do this
categorize_events[change["revid"]] = {"new": [], "removed": []} if change["revid"] not in categorize_events:
comment_to_match = re.sub('<.*?a>', '', change["parsedcomment"]) categorize_events[change["revid"]] = {"new": [], "removed": []}
if recent_changes.mw_messages["recentchanges-page-added-to-category"].replace("[[:$1]]", "") in comment_to_match: comment_to_match = re.sub('<.*?a>', '', change["parsedcomment"])
categorize_events[change["revid"]]["new"].append(cat_title) if recent_changes.mw_messages["recentchanges-page-added-to-category"].replace("[[:$1]]", "") in comment_to_match:
logging.debug("Matched {} to added category for {}".format(cat_title, change["revid"])) categorize_events[change["revid"]]["new"].append(cat_title)
elif recent_changes.mw_messages["recentchanges-page-removed-from-category"].replace("[[:$1]]", "") in comment_to_match: logging.debug("Matched {} to added category for {}".format(cat_title, change["revid"]))
categorize_events[change["revid"]]["removed"].append(cat_title) elif recent_changes.mw_messages["recentchanges-page-removed-from-category"].replace("[[:$1]]", "") in comment_to_match:
logging.debug("Matched {} to removed category for {}".format(cat_title, change["revid"])) categorize_events[change["revid"]]["removed"].append(cat_title)
logging.debug("Matched {} to removed category for {}".format(cat_title, change["revid"]))
else:
logging.debug("Unknown match for category change with messages {} and {} and comment_to_match {}".format(recent_changes.mw_messages["recentchanges-page-added-to-category"].replace("[[:$1]]", ""), recent_changes.mw_messages["recentchanges-page-removed-from-category"].replace("[[:$1]]", ""), comment_to_match))
else: else:
logging.debug("Unknown match for category change with messages {} and {} and comment_to_match {}".format(recent_changes.mw_messages["recentchanges-page-added-to-category"].replace("[[:$1]]", ""), recent_changes.mw_messages["recentchanges-page-removed-from-category"].replace("[[:$1]]", ""), comment_to_match)) logging.debug("Log entry got suppressed, ignoring entry.")
# if change["revid"] in categorize_events: # if change["revid"] in categorize_events:
# categorize_events[change["revid"]].append(cat_title) # categorize_events[change["revid"]].append(cat_title)
# else: # else:
@ -1063,10 +1070,14 @@ class recent_changes_class(object):
logging.debug(startup_info) logging.debug(startup_info)
recent_changes = recent_changes_class() recent_changes = Recent_Changes_Class()
if settings["wiki_bot_login"] and settings["wiki_bot_password"]: try:
recent_changes.log_in() if settings["wiki_bot_login"] and settings["wiki_bot_password"]:
recent_changes.init_info() recent_changes.log_in()
recent_changes.init_info()
except requests.exceptions.ConnectionError:
logging.critical("A connection can't be established with the wiki. Exiting...")
sys.exit(1)
time.sleep(1.0) time.sleep(1.0)
recent_changes.fetch(amount=settings["limitrefetch"] if settings["limitrefetch"] != -1 else settings["limit"]) recent_changes.fetch(amount=settings["limitrefetch"] if settings["limitrefetch"] != -1 else settings["limit"])