76def response(resp):
77 results = []
78
79 search_results = etree.XML(resp.content)
80
81 for entry in search_results.xpath('./result/doc'):
82 content = "No description available"
83 url = ""
84 title = ""
85 date = datetime.now()
86
87 for item in entry:
88 if item.attrib["name"] == "dcdate":
89 date = item.text
90
91 elif item.attrib["name"] == "dctitle":
92 title = item.text
93
94 elif item.attrib["name"] == "dclink":
95 url = item.text
96
97 elif item.attrib["name"] == "dcdescription":
98 content = item.text[:300]
99 if len(item.text) > 300:
100 content += "..."
101
102
103 publishedDate = None
104 for date_format in ['%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%d', '%Y-%m', '%Y']:
105 try:
106 publishedDate = datetime.strptime(date, date_format)
107 break
108 except:
109 pass
110
111 if publishedDate is not None:
112 res_dict = {'url': url, 'title': title, 'publishedDate': publishedDate, 'content': content}
113 else:
114 res_dict = {'url': url, 'title': title, 'content': content}
115
116 results.append(res_dict)
117
118 return results