-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilemanager.py
59 lines (30 loc) · 1.2 KB
/
filemanager.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
import urllib.request
def checkfileondisk(csv):
try:
open(csv+'.csv','r')
except FileNotFoundError:
return False
return True
def checkfilesondisk():
missing =[]
for csv in ['valid1','valid2','gares']:
isondisk = checkfileondisk(csv)
if isondisk == False:
missing += [csv]
return missing
def downloadmissing():
missing = checkfilesondisk()
for elt in missing:
downloadfile(elt)
print('done')
def downloadfile(FILE):
if FILE == "valid1":
URL = "https://opendata.stif.info/explore/dataset/validations-sur-le-reseau-ferre-nombre-de-validations-par-jour-1er-sem/download/?format=csv&timezone=Europe/Berlin&use_labels_for_header=true"
elif FILE == 'valid2':
URL = "https://opendata.stif.info/explore/dataset/validations-sur-le-reseau-ferre-nombre-de-validations-par-jour-2e-sem/download/?format=csv&timezone=Europe/Berlin&use_labels_for_header=true"
elif FILE == "gares":
URL = "https://opendata.stif.info/explore/dataset/emplacement-des-gares-idf/download/?format=csv&timezone=Europe/Berlin&use_labels_for_header=true"
else :
print('error')
return('error')
urllib.request.urlretrieve(URL, FILE+'.csv')