Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dbpedia Downloader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
swissbib
linked
linking
Dbpedia Downloader
Commits
692741fc
Commit
692741fc
authored
5 years ago
by
Jonas Waeber
Browse files
Options
Downloads
Patches
Plain Diff
add loop to retry download after 24h
delete old files does not repeat download of existing files.
parent
1ed8a15e
No related branches found
Branches containing commit
Tags
1.1.0
Tags containing commit
No related merge requests found
Pipeline
#58255
passed
5 years ago
Stage: publish
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/download.py
+36
-23
36 additions, 23 deletions
src/download.py
with
36 additions
and
23 deletions
src/download.py
+
36
−
23
View file @
692741fc
...
...
@@ -5,6 +5,7 @@ import yaml
from
yaml
import
BaseLoader
import
logging
import
requests
import
time
from
SPARQLWrapper
import
SPARQLWrapper
,
JSON
if
__name__
==
'
__main__
'
:
...
...
@@ -21,33 +22,45 @@ if __name__ == '__main__':
sparql
=
SPARQLWrapper
(
conf
[
'
sparql
'
][
'
endpoint
'
])
for
language
in
[
'
de
'
,
'
en
'
,
'
fr
'
,
'
it
'
,
'
commons
'
]:
with
open
(
conf
[
'
sparql
'
][
'
files
'
][
language
],
'
r
'
)
as
fp
:
query
=
fp
.
read
()
while
True
:
for
language
in
[
'
de
'
,
'
en
'
,
'
fr
'
,
'
it
'
,
'
commons
'
]:
with
open
(
conf
[
'
sparql
'
][
'
files
'
][
language
],
'
r
'
)
as
fp
:
query
=
fp
.
read
()
sparql
.
setQuery
(
query
)
sparql
.
setReturnFormat
(
JSON
)
results
=
sparql
.
query
().
convert
()
for
binding
in
results
[
'
results
'
][
'
bindings
'
]:
download_link
:
str
=
binding
[
'
file
'
][
'
value
'
]
latest_version
:
str
=
binding
[
'
latestVersion
'
][
'
value
'
].
replace
(
'
.
'
,
'
-
'
)
artifact
:
str
=
binding
[
'
artifact
'
][
'
value
'
]
file_name
=
f
'
{
latest_version
}
-
{
download_link
.
split
(
"
/
"
)[
-
1
]
}
'
sparql
.
setQuery
(
query
)
sparql
.
setReturnFormat
(
JSON
)
results
=
sparql
.
query
().
convert
()
for
binding
in
results
[
'
results
'
][
'
bindings
'
]:
download_link
:
str
=
binding
[
'
file
'
][
'
value
'
]
file_name_artifact
:
str
=
download_link
.
split
(
'
/
'
)[
-
1
]
latest_version
:
str
=
binding
[
'
latestVersion
'
][
'
value
'
].
replace
(
'
.
'
,
'
-
'
)
file_name
=
f
'
{
latest_version
}
-
{
file_name_artifact
}
'
logging
.
info
(
f
"
Download file from
{
download_link
}
.
"
)
with
requests
.
get
(
download_link
,
stream
=
True
)
as
response
:
if
response
.
ok
:
with
open
(
f
'
/tmp/
{
file_name
}
'
,
'
wb
'
)
as
f
:
for
chunk
in
response
.
iter_content
(
chunk_size
=
8192
):
if
chunk
:
# filter out keep-alive new chunks
f
.
write
(
chunk
)
shutil
.
move
(
f
'
/tmp/
{
file_name
}
'
,
f
'
{
conf
[
"
output
"
][
language
]
}
/
{
file_name
}
'
)
if
os
.
path
.
exists
(
f
"
{
conf
[
'
output
'
][
language
]
}
/
{
file_name
}
"
):
continue
else
:
# delete old files of the same artifact.
for
root
,
directories
,
files
in
os
.
walk
(
conf
[
'
output
'
][
language
]):
for
file
in
files
:
if
file_name_artifact
in
file
:
os
.
remove
(
os
.
path
.
join
(
root
,
file
))
logging
.
info
(
f
"
Download file from
{
download_link
}
.
"
)
with
requests
.
get
(
download_link
,
stream
=
True
)
as
response
:
if
response
.
ok
:
with
open
(
f
'
/tmp/
{
file_name
}
'
,
'
wb
'
)
as
f
:
for
chunk
in
response
.
iter_content
(
chunk_size
=
8192
):
if
chunk
:
# filter out keep-alive new chunks
f
.
write
(
chunk
)
shutil
.
move
(
f
'
/tmp/
{
file_name
}
'
,
f
'
{
conf
[
"
output
"
][
language
]
}
/
{
file_name
}
'
)
logging
.
info
(
f
"
Finished download from
{
download_link
}
into
{
conf
[
'
output
'
][
language
]
}
/
{
file_name
}
"
)
logging
.
info
(
"
Finished download for dbpedia.
"
)
logging
.
info
(
"
Now wait for 24h to check for newer dump!
"
)
time
.
sleep
(
86_400
)
# 24h
logging
.
info
(
f
"
Finished download from
{
download_link
}
into
{
conf
[
'
output
'
][
language
]
}
/
{
file_name
}
"
)
logging
.
info
(
"
Finished download for dbpedia.
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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