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
3e1c2153
Commit
3e1c2153
authored
Apr 13, 2019
by
Marc Abonce Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix] duckduckgo images requests
parent
34d85c8c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
5 deletions
+8
-5
duckduckgo_images.py
searx/engines/duckduckgo_images.py
+7
-4
test_duckduckgo_images.py
tests/unit/engines/test_duckduckgo_images.py
+1
-1
No files found.
searx/engines/duckduckgo_images.py
View file @
3e1c2153
...
...
@@ -35,9 +35,12 @@ site_url = 'https://duckduckgo.com/?{query}&iar=images&iax=1&ia=images'
# run query in site to get vqd number needed for requesting images
# TODO: find a way to get this number without an extra request (is it a hash of the query?)
def
get_vqd
(
query
):
res
=
get
(
site_url
.
format
(
query
=
urlencode
({
'q'
:
query
})))
def
get_vqd
(
query
,
headers
):
query_url
=
site_url
.
format
(
query
=
urlencode
({
'q'
:
query
}))
res
=
get
(
query_url
,
headers
=
headers
)
content
=
res
.
text
if
content
.
find
(
'vqd=
\'
'
)
==
-
1
:
raise
Exception
(
'Request failed'
)
vqd
=
content
[
content
.
find
(
'vqd=
\'
'
)
+
5
:]
vqd
=
vqd
[:
vqd
.
find
(
'
\'
'
)]
return
vqd
...
...
@@ -47,7 +50,7 @@ def get_vqd(query):
def
request
(
query
,
params
):
# to avoid running actual external requests when testing
if
'is_test'
not
in
params
:
vqd
=
get_vqd
(
query
)
vqd
=
get_vqd
(
query
,
params
[
'headers'
]
)
else
:
vqd
=
'12345'
...
...
@@ -74,7 +77,7 @@ def response(resp):
try
:
res_json
=
loads
(
content
)
except
:
r
eturn
[]
r
aise
Exception
(
'Cannot parse results'
)
# parse results
for
result
in
res_json
[
'results'
]:
...
...
tests/unit/engines/test_duckduckgo_images.py
View file @
3e1c2153
...
...
@@ -41,7 +41,7 @@ class TestDuckduckgoImagesEngine(SearxTestCase):
self
.
assertRaises
(
AttributeError
,
duckduckgo_images
.
response
,
'[]'
)
response
=
mock
.
Mock
(
text
=
'If this error persists, please let us know: ops@duckduckgo.com'
)
self
.
assert
Equal
(
duckduckgo_images
.
response
(
response
),
[]
)
self
.
assert
Raises
(
Exception
,
duckduckgo_images
.
response
,
response
)
json
=
u"""
{
...
...
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