37def response(resp):
38
39 img_results = []
40 text_results = []
41
42 search_results = json.loads(resp.text)
43
44
45 if 'data' not in search_results:
46 return []
47
48 posts = search_results.get('data', {}).get('children', [])
49
50
51 for post in posts:
52 data = post['data']
53
54
55 params = {'url': urljoin(base_url, data['permalink']), 'title': data['title']}
56
57
58 thumbnail = data['thumbnail']
59 url_info = urlparse(thumbnail)
60
61 if url_info[1] != '' and url_info[2] != '':
62 params['img_src'] = data['url']
63 params['thumbnail_src'] = thumbnail
64 params['template'] = 'images.html'
65 img_results.append(params)
66 else:
67 created = datetime.fromtimestamp(data['created_utc'])
68 content = data['selftext']
69 if len(content) > 500:
70 content = content[:500] + '...'
71 params['content'] = content
72 params['publishedDate'] = created
73 text_results.append(params)
74
75
76 return img_results + text_results