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

Create and save zip_dict to target_dir

parent 83bf2409
No related branches found
No related tags found
1 merge request!1New download
......@@ -41,9 +41,6 @@ def download_file(path: Path, 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
......@@ -108,13 +105,31 @@ def main():
flag_url = "http://fenixservices.fao.org/faostat/api/v1/en/definitions/types/flag"
# Download datasets.json
download_dataset_json(target_dir, dataset_url)
#download_dataset_json(target_dir, dataset_url)
# Download flags.json
download_flag_json(target_dir, flag_url)
#download_flag_json(target_dir, flag_url)
# Download main FAO file
download_file(target_dir, url)
#download_file(target_dir, url)
zip_dict = dict()
zip_file = zipfile.ZipFile('/Users/EnzoButhiot/Downloads/FAOSTAT.zip', 'r')
zip_list = zip_file.namelist()
for name in zip_list:
if name not in zip_dict.keys():
zip_dict[name] = list()
csv_list = []
for file in os.listdir(target_dir):
if ".csv" in file:
csv_list.append(file)
for zip in zip_list:
for csv in csv_list:
if zip.strip("_All_Data_(Normalized).zip") in csv:
zip_dict[zip].append(csv)
# Write zip_list into .txt file and save it to target_dir
with open(str(target_dir) + "/zip_dict.txt", 'w') as fd:
json.dump(zip_dict, fd)
if __name__ == '__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