Made file compilable on python2

This commit is contained in:
Frisk 2018-06-16 13:26:21 +02:00
parent 43c310e942
commit b23553fbda
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C

View file

@ -4,7 +4,6 @@
import time, logging, json, requests, datetime, re import time, logging, json, requests, datetime, re
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from collections import defaultdict from collections import defaultdict
from datetime import datetime
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
#logging.warning('Watch out!') #logging.warning('Watch out!')
#DEBUG, INFO, WARNING, ERROR, CRITICAL #DEBUG, INFO, WARNING, ERROR, CRITICAL
@ -41,7 +40,6 @@ def webhook_formatter(action, timestamp, **params):
if re.match(r"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b", params["author"]) is not None: if re.match(r"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b", params["author"]) is not None:
author_url = "https://{wiki}.gamepedia.com/Special:Contributions/{user}".format(wiki=settings["wiki"], user=params["author"]) author_url = "https://{wiki}.gamepedia.com/Special:Contributions/{user}".format(wiki=settings["wiki"], user=params["author"])
if params["author"] not in recent_changes.map_ips.keys(): if params["author"] not in recent_changes.map_ips.keys():
try:
contibs = safe_read(recent_changes.safe_request("https://{wiki}.gamepedia.com/api.php?action=query&format=json&list=usercontribs&uclimit=max&ucuser={user}&ucprop=".format(wiki=settings["wiki"], user=params["author"])), "query", "usercontribs") contibs = safe_read(recent_changes.safe_request("https://{wiki}.gamepedia.com/api.php?action=query&format=json&list=usercontribs&uclimit=max&ucuser={user}&ucprop=".format(wiki=settings["wiki"], user=params["author"])), "query", "usercontribs")
if contibs is None: if contibs is None:
logging.warning("WARNING: Something went wrong when checking amount of contributions for given IP address") logging.warning("WARNING: Something went wrong when checking amount of contributions for given IP address")
@ -154,7 +152,7 @@ def webhook_formatter(action, timestamp, **params):
elif event == 29: elif event == 29:
link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)')) link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)'))
embed["title"] = _("Replied to a comment on {target}'s profile").format(target=params["target"]) embed["title"] = _("Replied to a comment on {target}'s profile").format(target=params["target"])
elif event == 26 elif event == 26:
link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)')) link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)'))
embed["title"] = _("Edited a comment on {target}'s profile").format(target=params["target"]) embed["title"] = _("Edited a comment on {target}'s profile").format(target=params["target"])
elif event == 28: elif event == 28:
@ -365,7 +363,7 @@ def first_pass(change):
print (change) print (change)
send(_("Unable to process the event"), _("error"), "") send(_("Unable to process the event"), _("error"), "")
return return
elif change["type"] == "external": #not sure what happens then, but it's listed as possible type if change["type"] == "external": #not sure what happens then, but it's listed as possible type
logging.warning("External event happened, ignoring.") logging.warning("External event happened, ignoring.")
print (change) print (change)
return return
@ -393,7 +391,7 @@ class recent_changes(object):
if len(self.cache) == 0: if len(self.cache) == 0:
logging.debug("cache is empty, triggering clean fetch") logging.debug("cache is empty, triggering clean fetch")
clean = True clean = True
changes = safe_request("https://{wiki}.gamepedia.com/api.php?action=query&format=json&list=recentchanges&rcshow=!bot&rcprop=title%7Ctimestamp%7Cids%7Cloginfo%7Cparsedcomment%7Csizes%7Cflags%7Ctags%7Cuser&rclimit={amount}&rctype=edit%7Cnew%7Clog%7Cexternal".format(wiki=settings["wiki"], amount=settings["limit"])) changes = self.safe_request("https://{wiki}.gamepedia.com/api.php?action=query&format=json&list=recentchanges&rcshow=!bot&rcprop=title%7Ctimestamp%7Cids%7Cloginfo%7Cparsedcomment%7Csizes%7Cflags%7Ctags%7Cuser&rclimit={amount}&rctype=edit%7Cnew%7Clog%7Cexternal".format(wiki=settings["wiki"], amount=settings["limit"]))
if changes: if changes:
try: try:
changes = changes.json()['query']['recentchanges'] changes = changes.json()['query']['recentchanges']
@ -406,7 +404,7 @@ class recent_changes(object):
logging.warning("Wiki returned %s" % (request.json())) logging.warning("Wiki returned %s" % (request.json()))
return None return None
else: else:
for change in pchanges: for change in changes:
if change["rcid"] in self.ids: if change["rcid"] in self.ids:
continue continue
self.add_cache(change) self.add_cache(change)