-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_data_manager.py
More file actions
119 lines (101 loc) · 3.35 KB
/
add_data_manager.py
File metadata and controls
119 lines (101 loc) · 3.35 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""This is purely a utility file for adding entries to the .json files in the data folder. Don't call any functions from here."""
# THIS FILE IS CURRENTLY OUTDATED, DON'T USE
import json
import os
DATA_PATH = "data/"
class DataAdder:
def __init__(self, desc, filename, data_generator):
self.desc = desc
self.filename = filename
self.data_generator = data_generator
def add_data(self):
fp = DATA_PATH+self.filename+".json"
data_list = load_file(fp, [])
data_list.append(self.data_generator())
save_file(data_list, fp)
def get_lab_dict():
num = int(input("How many outcomes do you want the lab to have?"))
outcomes = []
for _ in range(num):
outcomes.append(
{
"description": "Description",
"min_sc": 0,
"max_sc": 10
}
)
return {
"name": "Name",
"description": "Description",
"outcomes": outcomes
}
def get_lecturer_dict():
data = {
"name": "Lecturer name here",
"subject": "Subject here",
"category": "Category here",
"trivia_messages": ["I'll say one of these things randomly before giving you a trivia question.", "Can you do this trivia question?"],
"level": 2
}
return data
def get_question_dict():
data = {
"question_title" : "Title of question",
"question_text" : "Add question text here",
"answers" : ['list', 'of', 'strings', 'that', 'will', 'be', 'mixed'],
"sc_reward" : 10,
"category" : "category name",
"image_name" : ""
}
return data
def get_item_dict():
data = {
"name" : "Item name",
"emoji" : "",
"cost" : 100,
"description" : "Item description",
"aliases": ["name1","name2","name3"],
"type":"standard"
}
if input("Is it a shop item? (y/n): ").lower() == "y":
data["shop_item"] = True
if input("Is it a booster? (y/n): ").lower() == "y":
data["boost"] = {
"category": "mechanics",
"bonus": 0.01,
"max_bonus": 0.1
}
return data
def get_len_of_list_in_file(name):
fp = DATA_PATH+name
data_list = load_file(fp, [])
return len(data_list)
def load_file(filename,default):
if os.path.exists(filename):
with open(filename, "r") as json_file:
data = json.load(json_file)
else:
data = default
return data
def save_file(data, filename):
with open(filename, "w") as f:
json.dump(data, f, sort_keys=True, indent=4)
def main():
while True:
options = [
DataAdder("Add trivia", "trivia_questions", get_question_dict),
DataAdder("Add main (tripos) questions", "main_questions", get_question_dict),
DataAdder("Add lecturer", "lecturers", get_lecturer_dict),
DataAdder("Add item", "items", get_item_dict),
DataAdder("Add lab", "labs", get_lab_dict)
]
for i, option in enumerate(options):
print("{}) {}".format(i, option.desc))
option = int(input("(Pick a number): "))
if isinstance(option, int):
if option >= 0 and option < len(options):
options[option].add_data()
print("Operation completed")
print("\n")
if __name__ == "__main__":
main()