-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcards.py
49 lines (43 loc) · 1.38 KB
/
cards.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
import json
# From https://github.com/crhallberg/json-against-humanity
# Structure:
# {
# "white": [],
# "black": [
# {
# "text": "text",
# "pick": 1
# }
# ],
# "packs": [
# {
# "name": "name",
# "official": True,
# "white": [0, 1, 2],
# "black": [0, 1, 2]
# }
# ]
# }
with open('cah-all-compact.json', 'r', encoding="utf8") as cah_all:
_CAH_ALL = json.load(cah_all)
_ALL_PACKS = [{"id": x, "name": _CAH_ALL["packs"][x]["name"], "official": _CAH_ALL["packs"][x]["official"]} for x in
range(len(_CAH_ALL["packs"]))]
class CardSet:
def __init__(self, index):
self.name = _CAH_ALL["packs"][index]["name"]
self.official = _CAH_ALL["packs"][index]["official"]
self.questions = []
self.answers = []
for q in filter(lambda x: _CAH_ALL["black"][x]["pick"] == 1, _CAH_ALL["packs"][index]["black"]):
self.questions.append(_CAH_ALL["black"][q]["text"])
for a in _CAH_ALL["packs"][index]["white"]:
self.answers.append(_CAH_ALL["white"][a])
# Just testing getting cards
if __name__ == '__main__':
print(json.dumps(_ALL_PACKS))
s = CardSet(0)
print(s.name)
for question in s.questions:
print("Question: " + question)
for answer in s.answers:
print("Answer: " + answer)