-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_json.py
146 lines (136 loc) · 6.14 KB
/
load_json.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#! python3
import json
import requests
import os
def load_json_files():
"""Get JSON files from GitHub and/or load JSON files."""
# Check if hero json file is downloaded
if os.path.exists('./data/hero_info_overwatch.json'):
# Loads/reads hero json file
with open('./data/hero_info_overwatch.json', encoding='utf-8') as f:
info_json = f.read()
# Saves data from hero json file to a variable
heroes_info = json.loads(info_json)
else:
input('Files from Github is about to be downloaded, press \'Enter\' to continue\n')
# Make a new folder called "data"
os.mkdir('data')
# If hero json file not found, get hero json data from GitHub,
# create a new hero json file and dump hero json data in the new file,
# then load the hero json data in a variable
print('Getting info about heroes data from GitHub...')
# Get hero json file from GitHub
get_hero_json = requests.get(
'https://raw.github.com/Crinibus/overwatch/master/data/hero_info_overwatch.json'
)
# Load hero json from string to dictionary
json_hero_data = get_hero_json.json()
print('Creating file with hero data...')
# Create new hero json file
with open('./data/hero_info_overwatch.json', 'w') as json_hero_file:
# Dump the hero json data in the new file and make it more readable
json.dump(
json_hero_data,
json_hero_file,
indent=4,
sort_keys=True
)
print('Done creating file\n')
# Loads/reads hero json file
with open('./data/hero_info_overwatch.json', encoding='utf-8') as f:
info_json = f.read()
# Saves data from hero json file to a variable
heroes_info = json.loads(info_json)
# Check if quiz json file is downloaded
if os.path.exists('./data/quiz_overwatch.json'):
# Loads/reads quiz json file
with open('./data/quiz_overwatch.json', encoding='utf-8') as f:
quiz_json = f.read()
# Saves data from quiz json file to a variable
quiz_questions = json.loads(quiz_json)
else:
input('Files from Github is about to be downloaded, press \'Enter\' to continue\n')
# If quiz json file not found, get quiz json data from GitHub,
# create a new quiz json file and dump quiz json data in the new file,
# then load the quiz json data in a variable
print('Getting quiz data from GitHub...')
# Get quiz json file from GitHub
get_quiz_json = requests.get(
'https://raw.github.com/Crinibus/overwatch/master/data/quiz_overwatch.json'
)
# Load quiz json from string to dictionary
json_quiz_data = get_quiz_json.json()
print('Creating file with quiz data...')
# Create new quiz json file
with open('./data/quiz_overwatch.json', 'w') as json_quiz_file:
# Dump the quiz json data in the new file and make it more readable
json.dump(
json_quiz_data,
json_quiz_file,
indent=4,
sort_keys=True
)
print('Done creating file\n')
# Loads/reads quiz json file
with open('./data/quiz_overwatch.json', encoding='utf-8') as f:
quiz_json = f.read()
# Saves data from quiz json file to a variable
quiz_questions = json.loads(quiz_json)
# Check if lists json file is downloaded
if os.path.exists('./data/lists_overwatch.json'):
# Loads/reads lists json file
with open('./data/lists_overwatch.json', encoding='utf-8') as f:
lists_json = f.read()
# Saves data from lists json file to a variable
lists = json.loads(lists_json)
HEROES_TANK = lists["HEROES_TANK"]
HEROES_DPS = lists["HEROES_DPS"]
HEROES_SUPPORT = lists["HEROES_SUPPORT"]
HEROES_ALL = lists["HEROES_ALL"]
GAMEMODES_ARCADE = lists["GAMEMODES_ARCADE"]
GAMEMODES_NORMAL = lists["GAMEMODES_NORMAL"]
GAMEMODES_ALL = lists["GAMEMODES_ALL"]
ROLE_ALL = lists["ROLE_ALL"]
else:
input('Files from Github is about to be downloaded, press \'Enter\' to continue\n')
# If lists json file not found, get lists json data from GitHub,
# create a new lists json file and dump lists json data in the new file,
# then load the lists json data in a variable
print('Getting lists data from GitHub...')
# Get lists json file from GitHub
get_lists_json = requests.get(
'https://raw.github.com/Crinibus/overwatch/master/data/lists_overwatch.json'
)
# Load lists json from string to dictionary
json_lists_data = get_lists_json.json()
print('Creating file with quiz data...')
# Create new lists json file
with open('./data/lists_overwatch.json', 'w') as json_lists_file:
# Dump the lists json data in the new file and make it more readable
json.dump(
json_lists_data,
json_lists_file,
indent=4,
sort_keys=True
)
print('Done creating file\n')
# Loads/reads lists json file
with open('./data/lists_overwatch.json', encoding='utf-8') as f:
lists_json = f.read()
# Saves data from lists json file to a variable
lists = json.loads(lists_json)
HEROES_TANK = lists["HEROES_TANK"]
HEROES_DPS = lists["HEROES_DPS"]
HEROES_SUPPORT = lists["HEROES_SUPPORT"]
HEROES_ALL = lists["HEROES_ALL"]
GAMEMODES_ARCADE = lists["GAMEMODES_ARCADE"]
GAMEMODES_NORMAL = lists["GAMEMODES_NORMAL"]
GAMEMODES_ALL = lists["GAMEMODES_ALL"]
ROLE_ALL = lists["ROLE_ALL"]
return heroes_info, quiz_questions, HEROES_TANK, HEROES_DPS, HEROES_SUPPORT, HEROES_ALL, GAMEMODES_ARCADE, GAMEMODES_NORMAL, GAMEMODES_ALL, ROLE_ALL
def get_images():
"""Not implemented yet."""
#print('Getting images from GitHub')
input('This feature is not yet implemented')
if __name__ == "__main__":
load_json_files()