-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
60 lines (49 loc) · 2.19 KB
/
script.py
File metadata and controls
60 lines (49 loc) · 2.19 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
import sys
import os
month_names = ['Gener','Febrer','Marc','Abril','Maig','Juny','Juliol','Agost','Setembre','Octubre','Novembre','Desembre']
months = range(1,13)
i2m = list(zip(months, month_names))
def download_data(year, dataset, link):
print("Current working directory before")
cwd = os.getcwd()
print(cwd)
print()
os.system(f"mkdir -p dades/{year}/{dataset}")
# trying to insert to false directory
try:
print(f"Working at-{cwd}/dades/{year}/{dataset}")
os.chdir(f"{cwd}/dades/{year}/{dataset}")
for month, month_name in i2m:
os.system(f"wget '{link}/{year}_{month:02d}_{month_name}_{dataset}.7z'")
os.system(f"7z x '{year}_{month:02d}_{month_name}_{dataset}.7z'")
os.system(f"rm '{year}_{month:02d}_{month_name}_{dataset}.7z'")
if month_name == 'Marc':
os.system(f"mv '{cwd}/dades/{year}/{dataset}/{year}_{month:02d}_Març_{dataset}.csv' '{cwd}/dades/{year}/{dataset}/{year}_{month:02d}_{month_name}_{dataset}.csv'")
if year == '2019':
print('correcting file names')
for month, month_name in i2m[2:5]:
if month_name == 'Marc':
month_name = 'Març'
if dataset=='BicingNou_ESTACIONS':
tochange='STAT'
elif dataset=='BicingNou_INFORMACIO':
tochange='INFO'
else:
break
os.system(f"mv '{cwd}/dades/{year}/{dataset}/{year}_{month:02d}_{month_name}_BICING2_{tochange}.csv' '{cwd}/dades/{year}/{dataset}/{year}_{month:02d}_{month_name}_{dataset}.csv'")
print(f"Done at-{cwd}/dades/{year}/{dataset}")
# Caching the exception
except:
print("Something wrong with specified directory. Exception- ")
print(sys.exc_info())
# handling with finally
finally:
print()
print("Restoring the path")
os.chdir(cwd)
print("Current directory is-", cwd)
if __name__ == "__main__":
year = sys.argv[1]
dataset = sys.argv[2]
link = sys.argv[3]
download_data(year,dataset,link)