-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_country.py
68 lines (46 loc) · 1.55 KB
/
add_country.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
#!/usr/bin/python
import sys
import os
import subprocess
from get_contours import get_contours
import os, shutil, fnmatch
import subprocess
import time
country_name_args=sys.argv[1]
style=sys.argv[2]
url=sys.argv[3]
start_time = time.perf_counter()
country_name_lower_case = country_name_args.lower().replace(" ", "_")
country_name_upper_case = country_name_lower_case.capitalize()
os.makedirs("dem/"+country_name_lower_case, exist_ok=True)
os.makedirs("carte_"+country_name_lower_case, exist_ok=True)
#Get Id
country_list=[]
#File country
file_in = open("country.txt", "rt")
lines = file_in.readlines()
for line in lines:
result = line.split(";")
country_list.append([result[0],result[1],result[2]])
file_in.close()
for idx, country in enumerate(country_list):
country_name=country[0].replace('#','')
if(country_name==country_name_args):
print("The country already exists")
sys.exit()
id=f'{int(country_list[len(country_list)-1][1])+1:02d}'
#File country
file_in = open("country.txt", "rt")
file_source = file_in.read()
file_modif = file_source+'\n'+country_name_args+';'+id+';'+style+';'+url+';1'
file_in.close()
file_out = open("country.txt", "wt")
file_out.write(file_modif)
file_out.close()
print("Start Add country"+country_name_args+ " "+id+ " "+" "+style,url)
#Get contours
get_contours(country_name_args, url)
#Launch script
subprocess.run(["bash", "update_map.sh",country_name_args,id,style,url])
stop_time = time.perf_counter()
print("End Add country in "+time.strftime('%H:%M:%S', time.gmtime(stop_time - start_time)))