149def response(resp):
150 results = []
151
152 raw_search_results = loads(resp.text)
153
154
155 if not raw_search_results:
156 return []
157
158 search_results = raw_search_results.get('channels', [])
159
160 if len(search_results) == 0:
161 return []
162
163 for result in search_results[0].get('items', []):
164
165 if search_type == 'image':
166 result_url = ''
167 if 'url' in result:
168 result_url = result['url']
169 elif 'link' in result:
170 result_url = result['link']
171 else:
172 continue
173
174
175 results.append(
176 {
177 'url': result_url,
178 'title': result['title'],
179 'content': '',
180 'img_src': result['image'],
181 'template': 'images.html',
182 }
183 )
184
185
186 else:
187 publishedDate = None
188 if 'pubDate' in result:
189 publishedDate = parser.parse(result['pubDate'])
190
191
192 results.append(
193 {
194 'url': result['link'] or '',
195 'title': result['title'],
196 'content': html_to_text(result['description']),
197 'publishedDate': publishedDate,
198 }
199 )
200
201
202
203 return results