-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
64 lines (52 loc) · 2.33 KB
/
main.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
from multiprocessing import Process
from os import path
from db.inserter import update_db
from utils import *
from utils.constants import *
from utils.update_localization import generate_locales
from utils.updater import update_dataset, update_images
from dotenv import load_dotenv
load_dotenv("/utils/.env")
def get_vehicle_by_country(country, fetch_uri, file_in_path, vehicle_type="VEHICLE", verbose=False):
all_vehicles = getJson(path.join(".", "nations", country, file_in_path))
if all_vehicles is None:
if verbose: cLogger.warning(f'{vehicle_type.upper()} doesn\'t have a file called {file_in_path}')
return
out_file = path.join(".", "nations", country, f"{country}Final{vehicle_type}s.json")
final_vehicles = []
for index, vehicle in enumerate(all_vehicles):
if verbose: cLogger.info(f'{index:2} -> {country.upper()} {vehicle_type.upper()} {vehicle}')
try:
vehicle = create_vehicle(vehicle, fetch_uri)
if vehicle is None:
continue
final_vehicles.append(vehicle)
except Exception as e:
e.with_traceback()
cLogger.error(f'Error creating {vehicle_type} {vehicle} -> {e.with_traceback()}')
continue
with open(out_file, 'w') as f:
json.dump([o.toJson() for o in final_vehicles], f, indent=2)
def process_country(nation, verbose):
get_vehicle_by_country(nation, VEHICLE_FETCH_URI['ground'], f'country_{nation}_ground.json', 'Tank', verbose)
get_vehicle_by_country(nation, VEHICLE_FETCH_URI['sea'], f'country_{nation}_sea.json', 'Ship', verbose)
get_vehicle_by_country(nation, VEHICLE_FETCH_URI['air'], f'country_{nation}_air.json', 'Aircraft', verbose)
def main(verbose: bool = False, use_multiprocessing: bool = True):
if use_multiprocessing:
processes = []
for nation in COUNTRIES:
p = Process(target=process_country, args=(nation, verbose))
p.start()
processes.append(p)
for p in processes:
p.join()
else:
for nation in COUNTRIES:
process_country(nation, verbose)
if __name__ == '__main__':
update_dataset()
# TODO: Fix localization for weaponry when using multiprocessing
main(verbose=True, use_multiprocessing=False)
update_db()
update_images()
generate_locales("./locales")