88def response(resp):
89 """Get response from google's search request"""
90 results = []
91
92 detect_google_sorry(resp)
93
94 json_start = resp.text.find('{"ischj":')
95 json_data = loads(resp.text[json_start:])
96
97 for item in json_data["ischj"].get("metadata", []):
98 result_item = {
99 'url': item["result"]["referrer_url"],
100 'title': item["result"]["page_title"],
101 'content': item["text_in_grid"]["snippet"],
102 'source': item["result"]["site_title"],
103 'resolution': f'{item["original_image"]["width"]} x {item["original_image"]["height"]}',
104 'img_src': item["original_image"]["url"],
105 'thumbnail_src': item["thumbnail"]["url"],
106 'template': 'images.html',
107 }
108
109 author = item["result"].get('iptc', {}).get('creator')
110 if author:
111 result_item['author'] = ', '.join(author)
112
113 copyright_notice = item["result"].get('iptc', {}).get('copyright_notice')
114 if copyright_notice:
115 result_item['source'] += ' | ' + copyright_notice
116
117 freshness_date = item["result"].get("freshness_date")
118 if freshness_date:
119 result_item['source'] += ' | ' + freshness_date
120
121 file_size = item.get('gsa', {}).get('file_size')
122 if file_size:
123 result_item['source'] += ' (%s)' % file_size
124
125 results.append(result_item)
126
127 return results