-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgetzips.py
49 lines (36 loc) · 2.21 KB
/
getzips.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
import os
command = "curl -O https://data.cityofnewyork.us/api/file_data/YObIR0MbpUVA0EpQzZSq5x55FzKGM2ejSeahdvjqR20?filename=ZIP_CODE_040114.zip"
name = "YObIR0MbpUVA0EpQzZSq5x55FzKGM2ejSeahdvjqR20?filename=ZIP_CODE_040114.zip"
def getzips():
'''The function downloads a zipcode shape file into the PUIDATA directory from the NYC Open data
Author: vys217 referring code from
https://github.com/fedhere/PUI2016_fb55/blob/master/HW3_fb55/citibikes_gender.ipynb
'''
if not os.path.isfile(os.getenv("PUIDATA") + "/" + "ZIP_CODE_040114.shp"):
# if in the current file just move it to PUIData
if os.path.isfile("ZIP_CODE_040114.shp"):
print ('files in current directory, moving it to PUIdata')
if os.system("mv " + "ZIP_CODE* " + os.getenv("PUIDATA")):
print ("Error moving files!, Please check!")
#otherwise start looking for the zip file
else:
# Check if zip file in PUIdata
if not os.path.isfile(os.getenv("PUIDATA") + "/" + name):
# Check zip file in current directory
if not os.path.isfile(name):
# Download zip file if not in PUIdata and current directory
print ('Downloading')
os.system(command)
#Move Zip file to PUIdata
os.system("mv " + name + ' ' + os.getenv("PUIDATA"))
### unzip the zip file, it gets unzipped to current directory
if not os.system("unzip " + os.getenv("PUIDATA") + "/" + name):
print("Unzipped")
# Move the unzipped folder to PUIData
if os.system("mv " + "ZIP_CODE*" + ' ' + os.getenv("PUIDATA")):
print ("Error moving files!, Please check!")
### One final check:
if not os.path.isfile(os.getenv("PUIDATA") + "/" + "ZIP_CODE_040114.shp"):
print ("WARNING!!! something is wrong: the file is not there!")
else:
print ("Folder with required files in PUIdata, you can continue")