Skip to content
Snippets Groups Projects
Commit cb84ff84 authored by Enzo Buthiot's avatar Enzo Buthiot
Browse files

Write list of zip into .txt file

parent 90b817ca
No related branches found
No related tags found
1 merge request!1New download
......@@ -27,6 +27,7 @@ import logging
import sys, os
import requests
import zipfile
import json
from io import BytesIO
from zipfile import ZipFile
from pathlib import Path
......@@ -38,6 +39,11 @@ def download_file(path: Path, url):
print("Downloading database from ", url)
resp = requests.get(url)
with ZipFile(BytesIO(resp.content)) as zfile:
# Get list of zip names
zip_list = zfile.namelist()
# Write zip_list into .txt file and save it to target_dir
with open(str(path) + "/zip_list.txt", 'w') as fd:
json.dump(zip_list, fd)
# Extract all files from zip and store it to path
zfile.extractall(path)
# Unzip all files then delete zip files
......@@ -110,6 +116,24 @@ def main():
# Download main FAO file
download_file(target_dir, url)
# Then loads datasets.json file
datasets_info_list = None
fd = open(target_dir / "datasets.json", 'rt', encoding='latin-1')
datasets_info_list = json.load(fd)['Datasets']['Dataset']
#or dataset in datasets_info_list:
#print(Path(dataset['FileLocation']).name)
zip_file = zipfile.ZipFile('/Users/EnzoButhiot/Downloads/FAOSTAT.zip', 'r')
zip_list = zip_file.namelist()
with open(str(target_dir) + "/zip_list.txt", 'w') as fd:
json.dump(zip_list, fd)
#with open(str(target_dir) + '/zipfile_list.txt', 'w') as fd:
# for name in zip_file.namelist():
# fd.write('%s\n' % name)
# print('%s' % (name))
zip_file.close()
if __name__ == '__main__':
sys.exit(main())
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment