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