.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.flickr_noapi Namespace Reference

Functions

 build_flickr_url (user_id, photo_id)
 
 _get_time_range_url (time_range)
 
 request (query, params)
 
 response (resp)
 

Variables

logging logger .Logger
 
dict about
 
list categories = ['images']
 
bool paging = True
 
bool time_range_support = True
 
bool safesearch = False
 
dict time_range_dict
 
tuple image_sizes = ('o', 'k', 'h', 'b', 'c', 'z', 'm', 'n', 't', 'q', 's')
 
str search_url = 'https://www.flickr.com/search?{query}&page={page}'
 
str time_range_url = '&min_upload_date={start}&max_upload_date={end}'
 
str photo_url = 'https://www.flickr.com/photos/{userid}/{photoid}'
 
 modelexport_re = re.compile(r"^\s*modelExport:\s*({.*}),$", re.M)
 

Detailed Description

Flickr (Images)

Function Documentation

◆ _get_time_range_url()

searx.engines.flickr_noapi._get_time_range_url ( time_range)
protected

Definition at line 53 of file flickr_noapi.py.

53def _get_time_range_url(time_range):
54 if time_range in time_range_dict:
55 return time_range_url.format(start=time(), end=str(int(time()) - time_range_dict[time_range]))
56 return ''
57
58

Referenced by searx.engines.flickr_noapi.request().

+ Here is the caller graph for this function:

◆ build_flickr_url()

searx.engines.flickr_noapi.build_flickr_url ( user_id,
photo_id )

Definition at line 49 of file flickr_noapi.py.

49def build_flickr_url(user_id, photo_id):
50 return photo_url.format(userid=user_id, photoid=photo_id)
51
52

Referenced by searx.engines.flickr_noapi.response().

+ Here is the caller graph for this function:

◆ request()

searx.engines.flickr_noapi.request ( query,
params )

Definition at line 59 of file flickr_noapi.py.

59def request(query, params):
60 params['url'] = search_url.format(query=urlencode({'text': query}), page=params['pageno']) + _get_time_range_url(
61 params['time_range']
62 )
63 return params
64
65

References searx.engines.flickr_noapi._get_time_range_url().

+ Here is the call graph for this function:

◆ response()

searx.engines.flickr_noapi.response ( resp)

Definition at line 66 of file flickr_noapi.py.

66def response(resp): # pylint: disable=too-many-branches
67 results = []
68
69 matches = modelexport_re.search(resp.text)
70 if matches is None:
71 return results
72
73 match = matches.group(1)
74 model_export = json.loads(match)
75
76 if 'legend' not in model_export:
77 return results
78 legend = model_export['legend']
79
80 # handle empty page
81 if not legend or not legend[0]:
82 return results
83
84 for x, index in enumerate(legend):
85 if len(index) != 8:
86 logger.debug("skip legend enty %s : %s", x, index)
87 continue
88
89 photo = model_export['main'][index[0]][int(index[1])][index[2]][index[3]][index[4]][index[5]][int(index[6])][
90 index[7]
91 ]
92 author = ecma_unescape(photo.get('realname', ''))
93 source = ecma_unescape(photo.get('username', ''))
94 if source:
95 source += ' @ Flickr'
96 title = ecma_unescape(photo.get('title', ''))
97 content = html_to_text(ecma_unescape(photo.get('description', '')))
98 img_src = None
99
100 # From the biggest to the lowest format
101 size_data = None
102 for image_size in image_sizes:
103 if image_size in photo['sizes']['data']:
104 size_data = photo['sizes']['data'][image_size]['data']
105 break
106
107 if not size_data:
108 logger.debug('cannot find valid image size: {0}'.format(repr(photo['sizes']['data'])))
109 continue
110
111 img_src = size_data['url']
112 resolution = f"{size_data['width']} x {size_data['height']}"
113
114 # For a bigger thumbnail, keep only the url_z, not the url_n
115 if 'n' in photo['sizes']['data']:
116 thumbnail_src = photo['sizes']['data']['n']['data']['url']
117 elif 'z' in photo['sizes']['data']:
118 thumbnail_src = photo['sizes']['data']['z']['data']['url']
119 else:
120 thumbnail_src = img_src
121
122 if 'ownerNsid' not in photo:
123 # should not happen, disowned photo? Show it anyway
124 url = img_src
125 else:
126 url = build_flickr_url(photo['ownerNsid'], photo['id'])
127
128 result = {
129 'url': url,
130 'img_src': img_src,
131 'thumbnail_src': thumbnail_src,
132 'source': source,
133 'resolution': resolution,
134 'template': 'images.html',
135 }
136 result['author'] = author.encode(errors='ignore').decode()
137 result['source'] = source.encode(errors='ignore').decode()
138 result['title'] = title.encode(errors='ignore').decode()
139 result['content'] = content.encode(errors='ignore').decode()
140 results.append(result)
141
142 return results

References searx.engines.flickr_noapi.build_flickr_url(), and searx.format.

+ Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.flickr_noapi.about
Initial value:
1= {
2 "website": 'https://www.flickr.com',
3 "wikidata_id": 'Q103204',
4 "official_api_documentation": 'https://secure.flickr.com/services/api/flickr.photos.search.html',
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'HTML',
8}

Definition at line 20 of file flickr_noapi.py.

◆ categories

list searx.engines.flickr_noapi.categories = ['images']

Definition at line 30 of file flickr_noapi.py.

◆ image_sizes

tuple searx.engines.flickr_noapi.image_sizes = ('o', 'k', 'h', 'b', 'c', 'z', 'm', 'n', 't', 'q', 's')

Definition at line 41 of file flickr_noapi.py.

◆ logger

logging searx.engines.flickr_noapi.logger .Logger

Definition at line 17 of file flickr_noapi.py.

◆ modelexport_re

searx.engines.flickr_noapi.modelexport_re = re.compile(r"^\s*modelExport:\s*({.*}),$", re.M)

Definition at line 46 of file flickr_noapi.py.

◆ paging

bool searx.engines.flickr_noapi.paging = True

Definition at line 31 of file flickr_noapi.py.

◆ photo_url

str searx.engines.flickr_noapi.photo_url = 'https://www.flickr.com/photos/{userid}/{photoid}'

Definition at line 45 of file flickr_noapi.py.

◆ safesearch

bool searx.engines.flickr_noapi.safesearch = False

Definition at line 33 of file flickr_noapi.py.

◆ search_url

str searx.engines.flickr_noapi.search_url = 'https://www.flickr.com/search?{query}&page={page}'

Definition at line 43 of file flickr_noapi.py.

◆ time_range_dict

dict searx.engines.flickr_noapi.time_range_dict
Initial value:
1= {
2 'day': 60 * 60 * 24,
3 'week': 60 * 60 * 24 * 7,
4 'month': 60 * 60 * 24 * 7 * 4,
5 'year': 60 * 60 * 24 * 7 * 52,
6}

Definition at line 35 of file flickr_noapi.py.

◆ time_range_support

bool searx.engines.flickr_noapi.time_range_support = True

Definition at line 32 of file flickr_noapi.py.

◆ time_range_url

str searx.engines.flickr_noapi.time_range_url = '&min_upload_date={start}&max_upload_date={end}'

Definition at line 44 of file flickr_noapi.py.