Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
searx-engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
searx-engine
Commits
d7ea44ab
Commit
d7ea44ab
authored
Jan 11, 2015
by
Adam Tauber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix] dates before 1900
parent
23fa74b5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
16 deletions
+6
-16
wikidata.py
searx/engines/wikidata.py
+6
-16
No files found.
searx/engines/wikidata.py
View file @
d7ea44ab
import
json
from
requests
import
get
from
urllib
import
urlencode
import
locale
import
dateutil.parser
from
searx.utils
import
format_date_by_locale
result_count
=
1
wikidata_host
=
'https://www.wikidata.org'
...
...
@@ -38,27 +37,18 @@ def response(resp):
if
language
==
'all'
:
language
=
'en'
try
:
locale
.
setlocale
(
locale
.
LC_ALL
,
str
(
resp
.
search_params
[
'language'
]))
except
:
try
:
locale
.
setlocale
(
locale
.
LC_ALL
,
'en_US'
)
except
:
pass
pass
url
=
url_detail
.
format
(
query
=
urlencode
({
'ids'
:
'|'
.
join
(
wikidata_ids
),
'languages'
:
language
+
'|en'
}))
htmlresponse
=
get
(
url
)
jsonresponse
=
json
.
loads
(
htmlresponse
.
content
)
for
wikidata_id
in
wikidata_ids
:
results
=
results
+
getDetail
(
jsonresponse
,
wikidata_id
,
language
)
results
=
results
+
getDetail
(
jsonresponse
,
wikidata_id
,
language
,
resp
.
search_params
[
'language'
]
)
return
results
def
getDetail
(
jsonresponse
,
wikidata_id
,
language
):
def
getDetail
(
jsonresponse
,
wikidata_id
,
language
,
locale
):
results
=
[]
urls
=
[]
attributes
=
[]
...
...
@@ -176,12 +166,12 @@ def getDetail(jsonresponse, wikidata_id, language):
date_of_birth
=
get_time
(
claims
,
'P569'
,
None
)
if
date_of_birth
is
not
None
:
date_of_birth
=
dateutil
.
parser
.
parse
(
date_of_birth
[
8
:])
.
strftime
(
locale
.
nl_langinfo
(
locale
.
D_FMT
)
)
date_of_birth
=
format_date_by_locale
(
date_of_birth
[
8
:],
locale
)
attributes
.
append
({
'label'
:
'Date of birth'
,
'value'
:
date_of_birth
})
date_of_death
=
get_time
(
claims
,
'P570'
,
None
)
if
date_of_death
is
not
None
:
date_of_death
=
dateutil
.
parser
.
parse
(
date_of_death
[
8
:])
.
strftime
(
locale
.
nl_langinfo
(
locale
.
D_FMT
)
)
date_of_death
=
format_date_by_locale
(
date_of_death
[
8
:],
locale
)
attributes
.
append
({
'label'
:
'Date of death'
,
'value'
:
date_of_death
})
if
len
(
attributes
)
==
0
and
len
(
urls
)
==
2
and
len
(
description
)
==
0
:
...
...
@@ -235,7 +225,7 @@ def get_string(claims, propertyName, defaultValue=None):
if
len
(
result
)
==
0
:
return
defaultValue
else
:
#TODO handle multiple urls
#
TODO handle multiple urls
return
result
[
0
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment