Download zip file using Python

https://www.zerotosingularity.com/blog/downloading-datasets-introducting-pdl/


import requests
import zipfile
import os

# download file
resp = requests.get(f"{url}{file}", allow_redirects=True, stream=True)

filename = f"{download_dir}{file}"

zfile = open(filename, 'wb')
zfile.write(resp.content)
zfile.close()

zipf = zipfile.ZipFile(filename, 'r')
zipf.extractall(download_dir)
zipf.close()

os.remove(filename)



YEAR=2015
for MONTH=`seq -w 1 12`; do
PARAMS="UserTableName...
RESPONSE=$(curl -X POST --data "$PARAMS"
http://www.transtats.bts.gov/DownLoad_Table.asp?Table_ID=236&Has_Group=3&Is_
Zipped=0)
echo "Received $RESPONSE"
ZIPFILE=$(echo $RESPONSE | tr '\"' '\n' | grep zip)
echo $ZIPFILE
curl -o $YEAR$MONTH.zip $ZIPFILE
done
Is this useful?
https://stackoverflow.com/questions/51665087/python-download-zip-file-from-restapi

Comments

Popular posts from this blog

How to create an organizational chart in your webpage using Google Organization Chart Tools

Embed JSX code with if condition in React app