-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
60 lines (48 loc) · 1.84 KB
/
utils.py
File metadata and controls
60 lines (48 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from collections import defaultdict
def generate_stats(memes):
if len(memes) == 0:
return {
"No memes":
"Try increasing the duration or posting some memes to change this ;)"
}
top_3_memes = sorted(memes, key=lambda m: m['upvotes'], reverse=True)[:3]
top_3_memes = [
f"<https://memes.party/?meme={m['id']}> {m['meme_score']}"
for m in top_3_memes
]
poaster_scores = defaultdict(int)
poaster_meme_counts = defaultdict(int)
upvotes_casted = 0
for m in memes:
poaster_scores[m['poaster']['username']] += m['meme_score']
poaster_meme_counts[m['poaster']['username']] += 1
upvotes_casted += m['upvotes']
poaster_scores = [(p, s) for p, s in poaster_scores.items()]
poaster_counts = [(p, c) for p, c in poaster_meme_counts.items()]
most_prolific_poaster = max(poaster_counts, key=lambda x: x[1])
def get_profile(username):
return f"<https://memes.party/profile/{username}>"
most_voted_memelords = sorted(poaster_scores,
key=lambda x: x[1],
reverse=True)[:3]
most_voted_memelords = [
f'{get_profile(m[0])} {m[1]} points' for m in most_voted_memelords
]
return {
"Total Memes":
len(memes),
"Active Registered Poasters":
len(set(m['poaster']['username'] for m in memes)),
"Most Prolific MemeLord":
f'{get_profile(most_prolific_poaster[0])} {most_prolific_poaster[1]} memes',
"Most Voted MemeLords":
most_voted_memelords,
"Most Voted Memes":
top_3_memes
}
def list_to_tab_str(l):
if type(l) is not list:
return l
return "".join(f'\n\t{v}' for v in l)
def discord_print_dict(d):
return '\n'.join(f'**{k}**: {list_to_tab_str(v)}' for k, v in d.items())