Skip to content

Instantly share code, notes, and snippets.

@prerakmody
Last active July 24, 2018 07:03
Show Gist options
  • Save prerakmody/e2dec6f6ea6d075483f151e0d269d532 to your computer and use it in GitHub Desktop.
Save prerakmody/e2dec6f6ea6d075483f151e0d269d532 to your computer and use it in GitHub Desktop.
Python Requests Lib
import os
import zipfile
import requests
def download_data(url_local, url_remote, root_dir):
with open(url__local, 'wb') as fp:
r = requests.get(url_remote)
fp.write(r.content)
zip_ref = zipfile.ZipFile(url_local, 'r')
zip_ref.extractall(root_dir)
zip_ref.close()
os.rename(os.path.join(root_dir, 'myfolder', 'myfile.txt'), os.path.join(root_dir, 'myfile.txt'))
os.removedirs(os.path.join(root_dir, 'myfolder'))
os.remove(url_local)
if __name__ == "__main__":
root_dir = ''
url_local = ''
url_remote = ''
download_data(url_local, url_remote, root_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment