Made the tags section show tag display name instead of internal name

This commit is contained in:
Frisk 2018-06-25 12:45:48 +02:00
parent d8169f1486
commit e69e342df1
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C
2 changed files with 42 additions and 24 deletions

View file

@ -5,7 +5,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2018-06-25 11:08+0200\n" "POT-Creation-Date: 2018-06-25 12:45+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -177,7 +177,7 @@ msgstr ""
msgid "none" msgid "none"
msgstr "" msgstr ""
#: rcgcdw.py:224 rcgcdw.py:337 #: rcgcdw.py:224 rcgcdw.py:349
msgid "No description provided" msgid "No description provided"
msgstr "" msgstr ""
@ -269,87 +269,87 @@ msgstr ""
msgid "Created a tag \"{tag}\"" msgid "Created a tag \"{tag}\""
msgstr "" msgstr ""
#: rcgcdw.py:288 #: rcgcdw.py:289
msgid "Deleted a tag \"{tag}\"" msgid "Deleted a tag \"{tag}\""
msgstr "" msgstr ""
#: rcgcdw.py:291 #: rcgcdw.py:293
msgid "Activated a tag \"{tag}\"" msgid "Activated a tag \"{tag}\""
msgstr "" msgstr ""
#: rcgcdw.py:294 #: rcgcdw.py:296
msgid "Deactivated a tag \"{tag}\"" msgid "Deactivated a tag \"{tag}\""
msgstr "" msgstr ""
#: rcgcdw.py:431 #: rcgcdw.py:443
msgid "Unable to process the event" msgid "Unable to process the event"
msgstr "" msgstr ""
#: rcgcdw.py:431 #: rcgcdw.py:443
msgid "error" msgid "error"
msgstr "" msgstr ""
#: rcgcdw.py:511 #: rcgcdw.py:523
msgid "Daily overview" msgid "Daily overview"
msgstr "" msgstr ""
#: rcgcdw.py:527 #: rcgcdw.py:539
msgid " ({} actions)" msgid " ({} actions)"
msgstr "" msgstr ""
#: rcgcdw.py:528 #: rcgcdw.py:540
msgid " UTC ({} actions)" msgid " UTC ({} actions)"
msgstr "" msgstr ""
#: rcgcdw.py:530 rcgcdw.py:531 #: rcgcdw.py:542 rcgcdw.py:543
msgid "But nobody came" msgid "But nobody came"
msgstr "" msgstr ""
#: rcgcdw.py:536 #: rcgcdw.py:547
msgid "Admin actions" msgid "Admin actions"
msgstr "" msgstr ""
#: rcgcdw.py:536 #: rcgcdw.py:547
msgid "Bytes changed" msgid "Bytes changed"
msgstr "" msgstr ""
#: rcgcdw.py:536 #: rcgcdw.py:547
msgid "Day score" msgid "Day score"
msgstr "" msgstr ""
#: rcgcdw.py:536 #: rcgcdw.py:547
msgid "Edits made" msgid "Edits made"
msgstr "" msgstr ""
#: rcgcdw.py:536 #: rcgcdw.py:547
msgid "Most active hours" msgid "Most active hours"
msgstr "" msgstr ""
#: rcgcdw.py:536 #: rcgcdw.py:547
msgid "Most active users" msgid "Most active users"
msgstr "" msgstr ""
#: rcgcdw.py:536 #: rcgcdw.py:547
msgid "New articles" msgid "New articles"
msgstr "" msgstr ""
#: rcgcdw.py:536 #: rcgcdw.py:547
msgid "New files" msgid "New files"
msgstr "" msgstr ""
#: rcgcdw.py:536 #: rcgcdw.py:547
msgid "Unique contributors" msgid "Unique contributors"
msgstr "" msgstr ""
#: rcgcdw.py:649 #: rcgcdw.py:661
msgid "Connection status" msgid "Connection status"
msgstr "" msgstr ""
#: rcgcdw.py:649 #: rcgcdw.py:661
msgid "{wiki} seems to be down or unreachable." msgid "{wiki} seems to be down or unreachable."
msgstr "" msgstr ""
#: rcgcdw.py:659 #: rcgcdw.py:680
msgid "{wiki} is back up!" msgid "{wiki} is back up!"
msgstr "" msgstr ""

View file

@ -283,9 +283,11 @@ def webhook_formatter(action, STATIC, **params):
elif action == 34: elif action == 34:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
embed["title"] = _("Created a tag \"{tag}\"").format(tag=params["additional"]["tag"]) embed["title"] = _("Created a tag \"{tag}\"").format(tag=params["additional"]["tag"])
recent_changes.update_tags()
elif action == 35: elif action == 35:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
embed["title"] = _("Deleted a tag \"{tag}\"").format(tag=params["additional"]["tag"]) embed["title"] = _("Deleted a tag \"{tag}\"").format(tag=params["additional"]["tag"])
recent_changes.update_tags()
elif action == 36: elif action == 36:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
embed["title"] = _("Activated a tag \"{tag}\"").format(tag=params["additional"]["tag"]) embed["title"] = _("Activated a tag \"{tag}\"").format(tag=params["additional"]["tag"])
@ -304,9 +306,15 @@ def webhook_formatter(action, STATIC, **params):
embed["color"] = random.randrange(1, 16777215) if colornumber is None else math.floor(colornumber) embed["color"] = random.randrange(1, 16777215) if colornumber is None else math.floor(colornumber)
embed["timestamp"] = STATIC["timestamp"] embed["timestamp"] = STATIC["timestamp"]
if STATIC["tags"]: if STATIC["tags"]:
tag_displayname = []
if "fields" not in embed: if "fields" not in embed:
embed["fields"] = [] embed["fields"] = []
embed["fields"].append({"name": "Tags", "value": ", ".join(STATIC["tags"])}) for tag in STATIC["tags"]:
if tag in recent_changes.tags:
tag_displayname.append(recent_changes.tags[tag])
else:
tag_displayname.append(tag)
embed["fields"].append({"name": "Tags", "value": ", ".join(tag_displayname)})
data["embeds"].append(dict(embed)) data["embeds"].append(dict(embed))
data['avatar_url'] = settings["avatars"]["embed"] data['avatar_url'] = settings["avatars"]["embed"]
formatted_embed = json.dumps(data, indent=4) formatted_embed = json.dumps(data, indent=4)
@ -556,6 +564,7 @@ class recent_changes_class(object):
downtimecredibility = 0 downtimecredibility = 0
last_downtime = 0 last_downtime = 0
clock = 0 clock = 0
tags = {}
if settings["limitrefetch"] != -1: if settings["limitrefetch"] != -1:
with open("lastchange.txt", "r") as record: with open("lastchange.txt", "r") as record:
file_content = record.read().strip() file_content = record.read().strip()
@ -653,8 +662,17 @@ class recent_changes_class(object):
self.last_downtime = time.time() self.last_downtime = time.time()
def clear_cache(self): def clear_cache(self):
self.map_ips = {} self.map_ips = {}
def update_tags(self):
tags_read = safe_read(self.safe_request("https://{wiki}.gamepedia.com/api.php?action=query&format=json&list=tags&tgprop=name%7Cdisplayname".format(wiki=settings["wiki"])), "query", "tags")
if tags_read:
for tag in tags_read:
self.tags[tag["name"]] = (BeautifulSoup(tag["displayname"], "lxml")).get_text()
else:
logging.warning("Could not retrive tags. Internal names will be used!")
recent_changes = recent_changes_class() recent_changes = recent_changes_class()
recent_changes.update_tags()
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"])
schedule.every(settings["cooldown"]).seconds.do(recent_changes.fetch) schedule.every(settings["cooldown"]).seconds.do(recent_changes.fetch)