-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathconfig.py
More file actions
118 lines (89 loc) · 3.62 KB
/
config.py
File metadata and controls
118 lines (89 loc) · 3.62 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
import json
import os
from .language import Language
ROOT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
TEMPLATES_DIR = ROOT_DIR + "/templates"
STATIC_DIR = ROOT_DIR + "/static"
SUPPORTED_YEARS = []
DEFAULT_YEAR = "2024"
DEFAULT_AVATAR_FOLDER_PATH = "/static/images/avatars/"
AVATAR_SIZE = 200
AVATARS_NUMBER = 15
SUPPORTED_CHAPTERS = {}
SUPPORTED_LANGUAGES = {}
config_json = {}
timestamps_json = {}
contributors = {}
def get_config(year):
return config_json[year] if year in config_json else None
def get_timestamps_config():
return timestamps_json
def get_entries_from_json(json_config, p_key, s_key):
entries = []
if p_key in json_config:
for values in json_config.get(p_key):
entries.append(values.get(s_key))
return entries
def get_chapters(json_config):
chapters = []
data = get_entries_from_json(json_config, "outline", "chapters")
for list in data:
for entry in list:
chapters.append(entry.get("slug"))
return chapters
def get_languages(json_config):
languages = []
data = get_entries_from_json(json_config, "settings", "supported_languages")
for list in data:
for entry in list:
languages.append(getattr(Language, entry.upper().replace("-", "_")))
return languages
def get_live(json_config):
is_live = False
data = get_entries_from_json(json_config, "settings", "is_live")
for list in data:
if list is True:
is_live = True
return is_live
def update_config():
global timestamps_json
global contributors
config_files = []
for root, directories, files in os.walk(ROOT_DIR + "/config"):
for file in files:
if file == "last_updated.json":
config_filename = "config/%s" % file
with open(config_filename, "r") as config_file:
timestamps_json = json.load(config_file)
elif file == "contributors.json":
config_filename = "config/%s" % file
with open(config_filename, "r") as config_file:
contributors = json.load(config_file)
elif ".json" in file:
config_files.append(file[0:4])
# Sort the config files so read in year order
config_files.sort()
for year in config_files:
config_filename = "config/%s.json" % year
with open(config_filename, "r") as config_file:
json_config = json.load(config_file)
config_json[year] = json_config
if get_live(json_config):
SUPPORTED_YEARS.append(year)
SUPPORTED_LANGUAGES.update({year: get_languages(json_config)})
SUPPORTED_CHAPTERS.update({year: set(get_chapters(json_config))})
# Add the contributors details that contributed to this year
# for ease of look up later
json_config["contributors"] = {}
for contributor_id, contributor in contributors.items():
if (year in contributor["teams"]):
json_config["contributors"][contributor_id] = {**contributor}
json_config["contributors"][contributor_id]["teams"] = contributor["teams"][year]
for contributor_id, contributor in json_config["contributors"].items():
if "avatar_url" not in contributor:
contributor["avatar_url"] = (
DEFAULT_AVATAR_FOLDER_PATH
+ str(hash(contributor_id) % AVATARS_NUMBER)
+ ".jpg"
)
update_config()