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
cb84ff84
Commit
cb84ff84
authored
4 years ago
by
Enzo Buthiot
Browse files
Options
Downloads
Patches
Plain Diff
Write list of zip into .txt file
parent
90b817ca
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
+24
-0
24 additions, 0 deletions
download.py
with
24 additions
and
0 deletions
download.py
+
24
−
0
View file @
cb84ff84
...
...
@@ -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
())
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