-
Notifications
You must be signed in to change notification settings - Fork 0
/
pretty_hiscore.py
70 lines (58 loc) · 1.75 KB
/
pretty_hiscore.py
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
61
62
63
64
65
66
67
68
69
70
import os
from scores import ScoreRepository
from beautifultable import BeautifulTable
score_file = os.environ.get("SCORE_FILE", "../../scores.json")
if not os.path.isfile(score_file):
raise Exception(f"No Score file available: {score_file}")
JEDI_RANKS = [
"Grand Master",
"Master of the Order",
"Jedi Council Member",
"Jedi Master",
"Jedi Sentinel",
"Jedi Guardian",
"Jedi Battlemaster",
"Jedi Consular",
"Jedi Knight",
"Jedi Service Corps",
"Padawan",
"Youngling",
]
score_repo = ScoreRepository(filepath=score_file, backup_files=False)
ranked_hiscores = score_repo.ranked_user_scores
ranked_score = sorted({us.highest_score for us in ranked_hiscores}, reverse=1)
ranked_score_map = {score: rank for rank, score in enumerate(ranked_score, start=1)}
table = BeautifulTable(default_padding=2)
table.columns.header = ["Rank", "Jedi Rank", "User", "HiScore"]
for user_score in ranked_hiscores:
user_rank = ranked_score_map[user_score.highest_score]
jedi_rank = (
JEDI_RANKS[user_rank - 1] if user_rank < len(JEDI_RANKS) else JEDI_RANKS[-1]
)
table.rows.append(
[
f"#{user_rank}",
jedi_rank,
user_score.username,
f"{user_score.highest_score} points",
]
)
print(" - HiScores Table -")
print("")
print(table)
quotes = [
(
"“Once you start down the dark path, forever will it dominate your destiny.”",
"Yoda, The Empire Strikes Back",
),
("“Uuuuuuuuuuur Ahhhhrrr Uhrrr Ahhhhhhrrr Aaaaarhg.....”", "Chewbacca"),
]
print("\n\n\n\n")
for quote, author in quotes:
print(
f"""
{quote}
— {author}
"""
)
print("\n\n")