Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fao-fetcher
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dbnomics-fetchers
fao-fetcher
Commits
b8bde239
Commit
b8bde239
authored
4 years ago
by
Enzo Buthiot
Browse files
Options
Downloads
Patches
Plain Diff
Create and save zip_dict to target_dir
parent
83bf2409
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
New download
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
download.py
+21
-6
21 additions, 6 deletions
download.py
with
21 additions
and
6 deletions
download.py
+
21
−
6
View file @
b8bde239
...
...
@@ -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__
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment