mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-24 00:34:10 +00:00
Resolved #91
This commit is contained in:
parent
3ce102ba2d
commit
62f14cb5de
125
rcgcdw.py
125
rcgcdw.py
|
@ -1065,64 +1065,75 @@ def day_overview():
|
||||||
changed_bytes = 0
|
changed_bytes = 0
|
||||||
new_articles = 0
|
new_articles = 0
|
||||||
active_articles = []
|
active_articles = []
|
||||||
if not result[0] and not settings["send_empty_overview"]:
|
if not result[0]:
|
||||||
return # no changes in this day
|
if not settings["send_empty_overview"]:
|
||||||
for item in result[0]:
|
return # no changes in this day
|
||||||
if "actionhidden" in item or "suppressed" in item or "userhidden" in item:
|
else:
|
||||||
continue # while such actions have type value (edit/new/log) many other values are hidden and therefore can crash with key error, let's not process such events
|
embed = defaultdict(dict)
|
||||||
activity = add_to_dict(activity, item["user"])
|
embed["title"] = _("Daily overview")
|
||||||
hours = add_to_dict(hours, datetime.datetime.strptime(item["timestamp"], "%Y-%m-%dT%H:%M:%SZ").hour)
|
embed["url"] = create_article_path("Special:Statistics")
|
||||||
if item["type"] == "edit":
|
embed["description"] = _("No activity")
|
||||||
edits += 1
|
embed["color"] = settings["appearance"]["embed"]["daily_overview"]["color"]
|
||||||
changed_bytes += item["newlen"] - item["oldlen"]
|
embed["author"]["icon_url"] = settings["appearance"]["embed"]["daily_overview"]["icon"]
|
||||||
if item["ns"] == 0:
|
embed["author"]["name"] = settings["wikiname"]
|
||||||
articles = add_to_dict(articles, item["title"])
|
embed["author"]["url"] = create_article_path("")
|
||||||
if item["type"] == "new":
|
|
||||||
if item["ns"] == 0:
|
|
||||||
new_articles += 1
|
|
||||||
changed_bytes += item["newlen"]
|
|
||||||
if item["type"] == "log":
|
|
||||||
files = files + 1 if item["logtype"] == item["logaction"] == "upload" else files
|
|
||||||
admin = admin + 1 if item["logtype"] in ["delete", "merge", "block", "protect", "import", "rights",
|
|
||||||
"abusefilter", "interwiki", "managetags"] else admin
|
|
||||||
overall = round(new_articles + edits * 0.1 + files * 0.3 + admin * 0.1 + math.fabs(changed_bytes * 0.001), 2)
|
|
||||||
embed = defaultdict(dict)
|
|
||||||
embed["title"] = _("Daily overview")
|
|
||||||
embed["url"] = create_article_path("Special:Statistics")
|
|
||||||
embed["color"] = settings["appearance"]["embed"]["daily_overview"]["color"]
|
|
||||||
embed["author"]["icon_url"] = settings["appearance"]["embed"]["daily_overview"]["icon"]
|
|
||||||
embed["author"]["name"] = settings["wikiname"]
|
|
||||||
embed["author"]["url"] = create_article_path("")
|
|
||||||
if activity:
|
|
||||||
active_users = []
|
|
||||||
for user, numberu in Counter(activity).most_common(3): # find most active users
|
|
||||||
active_users.append(user + ngettext(" ({} action)", " ({} actions)", numberu).format(numberu))
|
|
||||||
for article, numbere in Counter(articles).most_common(3): # find most active users
|
|
||||||
active_articles.append(article + ngettext(" ({} edit)", " ({} edits)", numbere).format(numbere))
|
|
||||||
v = hours.values()
|
|
||||||
active_hours = []
|
|
||||||
for hour, numberh in Counter(hours).most_common(list(v).count(max(v))): # find most active hours
|
|
||||||
active_hours.append(str(hour))
|
|
||||||
houramount = ngettext(" UTC ({} action)", " UTC ({} actions)", numberh).format(numberh)
|
|
||||||
else:
|
else:
|
||||||
active_users = [_("But nobody came")] # a reference to my favorite game of all the time, sorry ^_^
|
for item in result[0]:
|
||||||
active_hours = [_("But nobody came")]
|
if "actionhidden" in item or "suppressed" in item or "userhidden" in item:
|
||||||
usramount = ""
|
continue # while such actions have type value (edit/new/log) many other values are hidden and therefore can crash with key error, let's not process such events
|
||||||
houramount = ""
|
activity = add_to_dict(activity, item["user"])
|
||||||
if not active_articles:
|
hours = add_to_dict(hours, datetime.datetime.strptime(item["timestamp"], "%Y-%m-%dT%H:%M:%SZ").hour)
|
||||||
active_articles = [_("But nobody came")]
|
if item["type"] == "edit":
|
||||||
embed["fields"] = []
|
edits += 1
|
||||||
edits, files, admin, changed_bytes, new_articles, unique_contributors, overall = daily_overview_sync(edits, files, admin, changed_bytes, new_articles, len(activity), overall)
|
changed_bytes += item["newlen"] - item["oldlen"]
|
||||||
fields = (
|
if item["ns"] == 0:
|
||||||
(ngettext("Most active user", "Most active users", len(active_users)), ', '.join(active_users)),
|
articles = add_to_dict(articles, item["title"])
|
||||||
(ngettext("Most edited article", "Most edited articles", len(active_articles)), ', '.join(active_articles)),
|
if item["type"] == "new":
|
||||||
(_("Edits made"), edits), (_("New files"), files), (_("Admin actions"), admin),
|
if item["ns"] == 0:
|
||||||
(_("Bytes changed"), changed_bytes), (_("New articles"), new_articles),
|
new_articles += 1
|
||||||
(_("Unique contributors"), unique_contributors),
|
changed_bytes += item["newlen"]
|
||||||
(ngettext("Most active hour", "Most active hours", len(active_hours)), ', '.join(active_hours) + houramount),
|
if item["type"] == "log":
|
||||||
(_("Day score"), overall))
|
files = files + 1 if item["logtype"] == item["logaction"] == "upload" else files
|
||||||
for name, value in fields:
|
admin = admin + 1 if item["logtype"] in ["delete", "merge", "block", "protect", "import", "rights",
|
||||||
embed["fields"].append({"name": name, "value": value})
|
"abusefilter", "interwiki", "managetags"] else admin
|
||||||
|
overall = round(new_articles + edits * 0.1 + files * 0.3 + admin * 0.1 + math.fabs(changed_bytes * 0.001), 2)
|
||||||
|
embed = defaultdict(dict)
|
||||||
|
embed["title"] = _("Daily overview")
|
||||||
|
embed["url"] = create_article_path("Special:Statistics")
|
||||||
|
embed["color"] = settings["appearance"]["embed"]["daily_overview"]["color"]
|
||||||
|
embed["author"]["icon_url"] = settings["appearance"]["embed"]["daily_overview"]["icon"]
|
||||||
|
embed["author"]["name"] = settings["wikiname"]
|
||||||
|
embed["author"]["url"] = create_article_path("")
|
||||||
|
if activity:
|
||||||
|
active_users = []
|
||||||
|
for user, numberu in Counter(activity).most_common(3): # find most active users
|
||||||
|
active_users.append(user + ngettext(" ({} action)", " ({} actions)", numberu).format(numberu))
|
||||||
|
for article, numbere in Counter(articles).most_common(3): # find most active users
|
||||||
|
active_articles.append(article + ngettext(" ({} edit)", " ({} edits)", numbere).format(numbere))
|
||||||
|
v = hours.values()
|
||||||
|
active_hours = []
|
||||||
|
for hour, numberh in Counter(hours).most_common(list(v).count(max(v))): # find most active hours
|
||||||
|
active_hours.append(str(hour))
|
||||||
|
houramount = ngettext(" UTC ({} action)", " UTC ({} actions)", numberh).format(numberh)
|
||||||
|
else:
|
||||||
|
active_users = [_("But nobody came")] # a reference to my favorite game of all the time, sorry ^_^
|
||||||
|
active_hours = [_("But nobody came")]
|
||||||
|
usramount = ""
|
||||||
|
houramount = ""
|
||||||
|
if not active_articles:
|
||||||
|
active_articles = [_("But nobody came")]
|
||||||
|
embed["fields"] = []
|
||||||
|
edits, files, admin, changed_bytes, new_articles, unique_contributors, overall = daily_overview_sync(edits, files, admin, changed_bytes, new_articles, len(activity), overall)
|
||||||
|
fields = (
|
||||||
|
(ngettext("Most active user", "Most active users", len(active_users)), ', '.join(active_users)),
|
||||||
|
(ngettext("Most edited article", "Most edited articles", len(active_articles)), ', '.join(active_articles)),
|
||||||
|
(_("Edits made"), edits), (_("New files"), files), (_("Admin actions"), admin),
|
||||||
|
(_("Bytes changed"), changed_bytes), (_("New articles"), new_articles),
|
||||||
|
(_("Unique contributors"), unique_contributors),
|
||||||
|
(ngettext("Most active hour", "Most active hours", len(active_hours)), ', '.join(active_hours) + houramount),
|
||||||
|
(_("Day score"), overall))
|
||||||
|
for name, value in fields:
|
||||||
|
embed["fields"].append({"name": name, "value": value, "inline": True})
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue