Last active
July 24, 2018 07:03
-
-
Save prerakmody/e2dec6f6ea6d075483f151e0d269d532 to your computer and use it in GitHub Desktop.
Python Requests Lib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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