| 
									
										
										
										
											2013-12-29 21:39:23 +01:00
										 |  |  | from json import loads | 
					
						
							| 
									
										
										
										
											2014-01-05 00:46:42 +01:00
										 |  |  | from urllib import urlencode | 
					
						
							| 
									
										
										
										
											2013-12-29 21:39:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | url = 'http://localhost:8090' | 
					
						
							|  |  |  | search_url = '/yacysearch.json?{query}&maximumRecords=10' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 02:31:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-29 21:39:23 +01:00
										 |  |  | def request(query, params): | 
					
						
							| 
									
										
										
										
											2014-01-20 02:31:20 +01:00
										 |  |  |     params['url'] = url + search_url.format(query=urlencode({'query': query})) | 
					
						
							| 
									
										
										
										
											2013-12-29 21:39:23 +01:00
										 |  |  |     return params | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 02:31:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-29 21:39:23 +01:00
										 |  |  | def response(resp): | 
					
						
							|  |  |  |     raw_search_results = loads(resp.text) | 
					
						
							| 
									
										
										
										
											2014-01-05 00:46:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-11 13:13:51 +01:00
										 |  |  |     if not raw_search_results: | 
					
						
							| 
									
										
										
										
											2013-12-29 21:39:23 +01:00
										 |  |  |         return [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     search_results = raw_search_results.get('channels', {})[0].get('items', []) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     results = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for result in search_results: | 
					
						
							|  |  |  |         tmp_result = {} | 
					
						
							|  |  |  |         tmp_result['title'] = result['title'] | 
					
						
							|  |  |  |         tmp_result['url'] = result['link'] | 
					
						
							| 
									
										
										
										
											2014-01-05 00:46:42 +01:00
										 |  |  |         tmp_result['content'] = '' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-11 13:13:51 +01:00
										 |  |  |         if result['description']: | 
					
						
							| 
									
										
										
										
											2014-01-20 02:31:20 +01:00
										 |  |  |             tmp_result['content'] += result['description'] + "<br/>" | 
					
						
							| 
									
										
										
										
											2013-12-29 21:39:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-11 13:13:51 +01:00
										 |  |  |         if result['pubDate']: | 
					
						
							| 
									
										
										
										
											2013-12-29 21:39:23 +01:00
										 |  |  |             tmp_result['content'] += result['pubDate'] + "<br/>" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if result['size'] != '-1': | 
					
						
							|  |  |  |             tmp_result['content'] += result['sizename'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         results.append(tmp_result) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return results |