-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsert_char.py
69 lines (59 loc) · 2.18 KB
/
insert_char.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
"""Insert new characters into the roles.json."""
import json
import requests
NIGHTSHEET_URL = "https://script.bloodontheclocktower.com/data/nightsheet.json"
JINXES_URL = "https://script.bloodontheclocktower.com/data/jinx.json"
JSON_FILEPATH = "./public/roles.json"
JSON_STRUCT = {
"id": "",
"name": "",
"team": "",
"image": "",
"firstNight": 0,
"firstNightReminder": "",
"otherNight": 0,
"otherNightReminder": "",
"reminders": [],
"setup": False,
"ability": "",
"jinxes": [],
}
def main():
"""Main function."""
name = input("Enter new character name: ").strip()
char_id = name.replace(" ", "").replace("-", "").lower()
JSON_STRUCT["name"] = name
JSON_STRUCT["id"] = char_id
JSON_STRUCT["image"] = (
f"https://raw.githubusercontent.com/tomozbot/botc-icons/refs/heads/main/WEBP/{char_id}.webp"
)
resp = requests.get(NIGHTSHEET_URL, timeout=10)
resp_json = resp.json()
first_order, other_order = resp_json["firstNight"], resp_json["otherNight"]
resp = requests.get(JINXES_URL, timeout=10)
resp_json = resp.json()
for entry in resp_json:
if entry["id"] == char_id:
JSON_STRUCT["jinxes"] = entry["jinx"]
with open(JSON_FILEPATH, "r", encoding="utf-8") as json_file:
role_json = json.load(json_file)
role_json.append(JSON_STRUCT)
for role in role_json:
if role["id"] in first_order:
role["firstNight"] = first_order.index(role["id"]) + 1
else:
role["firstNight"] = 0
if role["id"] in other_order:
role["otherNight"] = other_order.index(role["id"]) + 1
else:
role["otherNight"] = 0
with open(JSON_FILEPATH, "w", encoding="utf-8") as json_file:
json.dump(role_json, json_file)
print(f"First Night Dusk: {first_order.index('DUSK') + 1}")
print(f"Other Night Dusk: {other_order.index('DUSK') + 1}")
print(f"First Night Dawn: {first_order.index('DAWN') + 1}")
print(f"Other Night Dawn: {other_order.index('DAWN') + 1}")
print(f"Minion Info: {first_order.index('MINION') + 1}")
print(f"Demon Info: {first_order.index('DEMON') + 1}")
if __name__ == "__main__":
main()