File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change
1
+ #%%
1
2
import requests
3
+ import zipfile
4
+ import os
2
5
3
6
download_uris = [
4
7
"https://divvy-tripdata.s3.amazonaws.com/Divvy_Trips_2018_Q4.zip" ,
10
13
"https://divvy-tripdata.s3.amazonaws.com/Divvy_Trips_2220_Q1.zip" ,
11
14
]
12
15
16
+ def unzip_remove (ret , directory , name_file ):
17
+ open (f'{ directory } /{ name_file } .zip' , 'wb' ).write (ret .content )
18
+
19
+ with zipfile .ZipFile (f'{ directory } /{ name_file } .zip' ,"r" ) as zip_ref :
20
+ zip_ref .extractall (f"{ directory } " )
21
+
22
+ os .remove (f'{ directory } /{ name_file } .zip' )
23
+
24
+
13
25
14
26
def main ():
15
- # your code here
16
- pass
27
+ directory = "./downloads"
28
+ if not os .path .exists (directory ):
29
+ os .makedirs (directory )
30
+
31
+ for url in download_uris :
32
+ name_file = url .split ("/" )[- 1 ]
33
+ ret = requests .get (url )
34
+ if ret .status_code == 200 :
35
+ unzip_remove (ret , directory = directory , name_file = name_file )
36
+ else :
37
+ print (f"{ ret .status_code } - File Not found check URL: { url } " )
17
38
18
39
19
40
if __name__ == "__main__" :
20
41
main ()
42
+ #%%
You can’t perform that action at this time.
0 commit comments