-
Notifications
You must be signed in to change notification settings - Fork 75
/
generateGamesList.py
99 lines (83 loc) · 3.77 KB
/
generateGamesList.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
import urllib.request, urllib.parse
import json
response = urllib.request.urlopen(
'https://raw.githubusercontent.com/HamletDuFromage/switch-cheats-db/master/versions.json')
allVersions = json.load(response)
table = """# Games List
A list of all games with cheats.
The database currently contains {numCheats} cheat files for {numTitles} titles, of which {numCheatsWithLatest} have cheats for the latest version.
Key for cheat types:
- 🏃 FPS Cheats
- 🖥️ Resolution Cheats
- 🌄 Graphics Cheats
Key for latest status:
- 🟢 Latest Version Has Cheats
- 🟡 Latest Version Unknown
- 🔴 Latest Version Does Not Have Cheats
| NAME | TITLE ID | BUILD ID | VERSION | CHEAT TYPES | LATEST STATUS |
| --- | --- | --- | --- | --- | --- |
"""
numCheats = 0
numCheatsWithLatest = 0
tableItems = []
for title in os.listdir("titles"):
cheatsPath = os.path.join("titles", title, "cheats")
latestHasCheats = "🔴"
cheatFiles = [file for file in os.listdir(cheatsPath)]
hasFpsCheats = ""
hasResCheats = ""
hasGfxCheats = ""
# Check what type of cheats are available
for file in cheatFiles:
text = open(os.path.join(cheatsPath, file), "r").read().lower()
if "fps" in text:
hasFpsCheats = "🏃"
if "res" in text or "rrs" in text or "drs" in text:
hasResCheats = "🖥️"
if "gfx" in text or "shadow" in text:
hasGfxCheats = "🌄"
cheats = [file.removesuffix(".txt") for file in cheatFiles]
names = [file.removesuffix(".txt") for file in os.listdir(os.path.join("titles", title)) if file.endswith(".txt")]
if len(names) != 0:
name = names[0]
else:
name = "Unknown"
if(not title in allVersions):
# print(f"Missing version information for {title}")
versions = []
latestHasCheats = "🟡"
else:
versions = [version for version in allVersions[title].items() if version[1] in cheats]
versions.sort(key=lambda x: int(x[0]))
# If none of the build ids have a version, then we don't know if the latest version has cheats
if len(versions) == 0:
latestHasCheats = "🟡"
latest = [version[1] for version in allVersions[title].items() if version[0] == 'latest']
if len(latest) > 0:
latest = [version[1] for version in allVersions[title].items() if version[0] == str(latest[0])]
if(len(latest) > 0 and latest[0] in cheats):
latestHasCheats = "🟢"
numCheatsWithLatest += 1
# Add any cheats that don't have a version to the end of the list
versions += [(-1, cheat) for cheat in cheats if cheat not in [version[1] for version in versions]]
cheatsLinked = [f"[{version[1]}](titles/{title}/cheats/{version[1]}.txt)" for version in versions]
versionsLinked = [f"[{version[0]}](titles/{title}/cheats/{version[1]}.txt)" for version in versions if version[0] != -1]
nameLink = urllib.parse.quote(f"titles/{title}/{name}.txt")
tableItems.append(f"[{name}]({nameLink}) | [{title}](titles/{title}) | {', '.join(cheatsLinked)} | {', '.join(versionsLinked)} | {hasFpsCheats}{hasResCheats}{hasGfxCheats} | {latestHasCheats} |")
numCheats += len(cheats)
table = table.replace("{numCheats}", str(numCheats))
table = table.replace("{numTitles}", str(len(tableItems)))
table = table.replace("{numCheatsWithLatest}", str(numCheatsWithLatest))
tableItems.sort(key=str.lower)
table += "\n".join([item for item in tableItems])
if(os.path.exists("GAMES.md")):
existingGames = open("GAMES.md", "r", encoding="utf-16").read()
if existingGames != table:
open("GAMES.md", "w", encoding="utf-16").write(table)
print("true")
else:
print("false")
else:
open("GAMES.md", "w", encoding="utf-16").write(table)
print("true")