.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
flickr.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""
3
Flickr (Images)
4
5
More info on api-key : https://www.flickr.com/services/apps/create/
6
"""
7
8
from
json
import
loads
9
from
urllib.parse
import
urlencode
10
11
# about
12
about = {
13
"website"
:
'https://www.flickr.com'
,
14
"wikidata_id"
:
'Q103204'
,
15
"official_api_documentation"
:
'https://secure.flickr.com/services/api/flickr.photos.search.html'
,
16
"use_official_api"
:
True
,
17
"require_api_key"
:
True
,
18
"results"
:
'JSON'
,
19
}
20
21
categories = [
'images'
]
22
23
nb_per_page = 15
24
paging =
True
25
api_key =
None
26
27
28
url = (
29
'https://api.flickr.com/services/rest/?method=flickr.photos.search'
30
+
'&api_key={api_key}&{text}&sort=relevance'
31
+
'&extras=description%2C+owner_name%2C+url_o%2C+url_n%2C+url_z'
32
+
'&per_page={nb_per_page}&format=json&nojsoncallback=1&page={page}'
33
)
34
photo_url =
'https://www.flickr.com/photos/{userid}/{photoid}'
35
36
paging =
True
37
38
39
def
build_flickr_url
(user_id, photo_id):
40
return
photo_url.format(userid=user_id, photoid=photo_id)
41
42
43
def
request
(query, params):
44
params[
'url'
] = url.format(
45
text=urlencode({
'text'
: query}), api_key=api_key, nb_per_page=nb_per_page, page=params[
'pageno'
]
46
)
47
return
params
48
49
50
def
response
(resp):
51
results = []
52
53
search_results = loads(resp.text)
54
55
# return empty array if there are no results
56
if
'photos'
not
in
search_results:
57
return
[]
58
59
if
'photo'
not
in
search_results[
'photos'
]:
60
return
[]
61
62
photos = search_results[
'photos'
][
'photo'
]
63
64
# parse results
65
for
photo
in
photos:
66
if
'url_o'
in
photo:
67
img_src = photo[
'url_o'
]
68
elif
'url_z'
in
photo:
69
img_src = photo[
'url_z'
]
70
else
:
71
continue
72
73
# For a bigger thumbnail, keep only the url_z, not the url_n
74
if
'url_n'
in
photo:
75
thumbnail_src = photo[
'url_n'
]
76
elif
'url_z'
in
photo:
77
thumbnail_src = photo[
'url_z'
]
78
else
:
79
thumbnail_src = img_src
80
81
# append result
82
results.append(
83
{
84
'url'
:
build_flickr_url
(photo[
'owner'
], photo[
'id'
]),
85
'title'
: photo[
'title'
],
86
'img_src'
: img_src,
87
'thumbnail_src'
: thumbnail_src,
88
'content'
: photo[
'description'
][
'_content'
],
89
'author'
: photo[
'ownername'
],
90
'template'
:
'images.html'
,
91
}
92
)
93
94
# return results
95
return
results
searx.engines.flickr.response
response(resp)
Definition
flickr.py:50
searx.engines.flickr.request
request(query, params)
Definition
flickr.py:43
searx.engines.flickr.build_flickr_url
build_flickr_url(user_id, photo_id)
Definition
flickr.py:39
searxng
searx
engines
flickr.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0