Some small changes to the code to improve clarity

This commit is contained in:
Frisk 2018-09-30 23:48:12 +02:00
parent a75aa228f9
commit 61e0f95120
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C

View file

@ -128,8 +128,7 @@ def send_to_discord(data):
def webhook_formatter(action, STATIC, **params): def webhook_formatter(action, STATIC, **params):
logging.debug("Received things: {thing}".format(thing=params)) logging.debug("Received things: {thing}".format(thing=params))
colornumber = None if isinstance(STATIC["color"], str) else STATIC["color"] colornumber = None if isinstance(STATIC["color"], str) else STATIC["color"]
data = {} data = {"embeds": []}
data["embeds"] = []
embed = defaultdict(dict) embed = defaultdict(dict)
if "title" in params: if "title" in params:
article_encoded = params["title"].replace(" ", "_").replace(')', '\)') article_encoded = params["title"].replace(" ", "_").replace(')', '\)')
@ -161,7 +160,7 @@ def webhook_formatter(action, STATIC, **params):
if editsize > 6032: if editsize > 6032:
colornumber = 65280 colornumber = 65280
else: else:
colornumber = 35840 + (math.floor(editsize / (52))) * 256 colornumber = 35840 + (math.floor(editsize / 52)) * 256
elif editsize < 0: elif editsize < 0:
if editsize < -6032: if editsize < -6032:
colornumber = 16711680 colornumber = 16711680
@ -264,8 +263,8 @@ def webhook_formatter(action, STATIC, **params):
user=params["blocked_user"].replace(" ", "_").replace(')', user=params["blocked_user"].replace(" ", "_").replace(')',
'\)')) '\)'))
user = params["blocked_user"].split(':')[1] user = params["blocked_user"].split(':')[1]
time = _("infinity and beyond") if params["duration"] == "infinite" else params["duration"] block_time = _("infinity and beyond") if params["duration"] == "infinite" else params["duration"]
embed["title"] = _("Blocked {blocked_user} for {time}").format(blocked_user=user, time=time) embed["title"] = _("Blocked {blocked_user} for {time}").format(blocked_user=user, time=block_time)
elif action == "block/reblock": elif action == "block/reblock":
link = "https://{wiki}.gamepedia.com/{user}".format(wiki=settings["wiki"], link = "https://{wiki}.gamepedia.com/{user}".format(wiki=settings["wiki"],
user=params["blocked_user"].replace(" ", "_").replace(')', user=params["blocked_user"].replace(" ", "_").replace(')',
@ -505,7 +504,7 @@ def first_pass(
{"timestamp": change["timestamp"], "color": settings["appearance"]["suppressed"]["color"], {"timestamp": change["timestamp"], "color": settings["appearance"]["suppressed"]["color"],
"icon": settings["appearance"]["suppressed"]["icon"]}, user=change["user"]) "icon": settings["appearance"]["suppressed"]["icon"]}, user=change["user"])
return return
parse_output = HTMLParse.feed(change["parsedcomment"]) HTMLParse.feed(change["parsedcomment"])
# parsedcomment = (BeautifulSoup(change["parsedcomment"], "lxml")).get_text() # parsedcomment = (BeautifulSoup(change["parsedcomment"], "lxml")).get_text()
parsedcomment = HTMLParse.new_string parsedcomment = HTMLParse.new_string
HTMLParse.new_string = "" HTMLParse.new_string = ""
@ -674,7 +673,7 @@ def day_overview_request():
continuearg = request["continue"]["rccontinue"] if "continue" in request else None continuearg = request["continue"]["rccontinue"] if "continue" in request else None
except ValueError: except ValueError:
logging.warning("ValueError in fetching changes") logging.warning("ValueError in fetching changes")
self.downtime_controller() recent_changes.downtime_controller()
complete = 2 complete = 2
except KeyError: except KeyError:
logging.warning("Wiki returned %s" % (request.json())) logging.warning("Wiki returned %s" % (request.json()))
@ -747,7 +746,7 @@ def day_overview(): # time.strftime('%Y-%m-%dT%H:%M:%S.000Z', time.gmtime(time.
active_users = [] active_users = []
for user, numberu in Counter(activity).most_common(list(v).count(max(v))): # find most active users for user, numberu in Counter(activity).most_common(list(v).count(max(v))): # find most active users
active_users.append(user) active_users.append(user)
the_one = random.choice(active_users) # the_one = random.choice(active_users)
v = hours.values() v = hours.values()
active_hours = [] active_hours = []
for hour, numberh in Counter(hours).most_common(list(v).count(max(v))): # find most active users for hour, numberh in Counter(hours).most_common(list(v).count(max(v))): # find most active users
@ -769,8 +768,7 @@ def day_overview(): # time.strftime('%Y-%m-%dT%H:%M:%S.000Z', time.gmtime(time.
(_("Day score"), str(overall))) (_("Day score"), str(overall)))
for name, value in fields: for name, value in fields:
embed["fields"].append({"name": name, "value": value}) embed["fields"].append({"name": name, "value": value})
data = {} data = {"embeds": [dict(embed)]}
data["embeds"] = [dict(embed)]
formatted_embed = json.dumps(data, indent=4) formatted_embed = json.dumps(data, indent=4)
send_to_discord(formatted_embed) send_to_discord(formatted_embed)
else: else:
@ -954,7 +952,7 @@ class recent_changes_class(object):
logging.error("Failure when checking Internet connection at {time}".format( logging.error("Failure when checking Internet connection at {time}".format(
time=time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()))) time=time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())))
self.downtimecredibility = 0 self.downtimecredibility = 0
if looped == False: if not looped:
while 1: # recursed loop, check for connection (every 10 seconds) as long as three services are down, don't do anything else while 1: # recursed loop, check for connection (every 10 seconds) as long as three services are down, don't do anything else
if self.check_connection(looped=True): if self.check_connection(looped=True):
recent_changes.fetch(amount=settings["limitrefetch"]) recent_changes.fetch(amount=settings["limitrefetch"])
@ -964,7 +962,7 @@ class recent_changes_class(object):
return True return True
def downtime_controller(self): def downtime_controller(self):
if settings["show_updown_messages"] == False: if not settings["show_updown_messages"]:
return return
if self.streak > -1: # reset the streak of successful connections when bad one happens if self.streak > -1: # reset the streak of successful connections when bad one happens
self.streak = 0 self.streak = 0