| 
				
			 | 
			
			
				@@ -18,7 +18,6 @@ api_key = ''  # defined in settings.yml 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				18
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				19
			 | 
			
				19
			 | 
			
			
				 # xpath variables 
			 | 
		
	
		
			
			| 
				20
			 | 
			
				20
			 | 
			
			
				 failure_xpath = '/queryresult[attribute::success="false"]' 
			 | 
		
	
		
			
			| 
				21
			 | 
			
				
			 | 
			
			
				-answer_xpath = '//pod[attribute::primary="true"]/subpod/plaintext' 
			 | 
		
	
		
			
			| 
				22
			 | 
			
				21
			 | 
			
			
				 input_xpath = '//pod[starts-with(attribute::id, "Input")]/subpod/plaintext' 
			 | 
		
	
		
			
			| 
				23
			 | 
			
				22
			 | 
			
			
				 pods_xpath = '//pod' 
			 | 
		
	
		
			
			| 
				24
			 | 
			
				23
			 | 
			
			
				 subpods_xpath = './subpod' 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -76,11 +75,11 @@ def response(resp): 
			 | 
		
	
		
			
			| 
				76
			 | 
			
				75
			 | 
			
			
				     try: 
			 | 
		
	
		
			
			| 
				77
			 | 
			
				76
			 | 
			
			
				         infobox_title = search_results.xpath(input_xpath)[0].text 
			 | 
		
	
		
			
			| 
				78
			 | 
			
				77
			 | 
			
			
				     except: 
			 | 
		
	
		
			
			| 
				79
			 | 
			
				
			 | 
			
			
				-        infobox_title = None 
			 | 
		
	
		
			
			| 
				
			 | 
			
				78
			 | 
			
			
				+        infobox_title = "" 
			 | 
		
	
		
			
			| 
				80
			 | 
			
				79
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				81
			 | 
			
				80
			 | 
			
			
				     pods = search_results.xpath(pods_xpath) 
			 | 
		
	
		
			
			| 
				82
			 | 
			
				
			 | 
			
			
				-    result = "" 
			 | 
		
	
		
			
			| 
				83
			 | 
			
				81
			 | 
			
			
				     result_chunks = [] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+    result_content = "" 
			 | 
		
	
		
			
			| 
				84
			 | 
			
				83
			 | 
			
			
				     for pod in pods: 
			 | 
		
	
		
			
			| 
				85
			 | 
			
				84
			 | 
			
			
				         pod_id = pod.xpath(pod_id_xpath)[0] 
			 | 
		
	
		
			
			| 
				86
			 | 
			
				85
			 | 
			
			
				         pod_title = pod.xpath(pod_title_xpath)[0] 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -97,8 +96,9 @@ def response(resp): 
			 | 
		
	
		
			
			| 
				97
			 | 
			
				96
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				98
			 | 
			
				97
			 | 
			
			
				             if content and pod_id not in image_pods: 
			 | 
		
	
		
			
			| 
				99
			 | 
			
				98
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				100
			 | 
			
				
			 | 
			
			
				-                if pod_is_result: 
			 | 
		
	
		
			
			| 
				101
			 | 
			
				
			 | 
			
			
				-                    result = content 
			 | 
		
	
		
			
			| 
				
			 | 
			
				99
			 | 
			
			
				+                if pod_is_result or not result_content: 
			 | 
		
	
		
			
			| 
				
			 | 
			
				100
			 | 
			
			
				+                    if pod_id != "Input": 
			 | 
		
	
		
			
			| 
				
			 | 
			
				101
			 | 
			
			
				+                        result_content = "%s: %s" % (pod_title, content) 
			 | 
		
	
		
			
			| 
				102
			 | 
			
				102
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				103
			 | 
			
				103
			 | 
			
			
				                 # if no input pod was found, title is first plaintext pod 
			 | 
		
	
		
			
			| 
				104
			 | 
			
				104
			 | 
			
			
				                 if not infobox_title: 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -115,6 +115,8 @@ def response(resp): 
			 | 
		
	
		
			
			| 
				115
			 | 
			
				115
			 | 
			
			
				     if not result_chunks: 
			 | 
		
	
		
			
			| 
				116
			 | 
			
				116
			 | 
			
			
				         return [] 
			 | 
		
	
		
			
			| 
				117
			 | 
			
				117
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				118
			 | 
			
			
				+    title = "Wolfram|Alpha (%s)" % infobox_title 
			 | 
		
	
		
			
			| 
				
			 | 
			
				119
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				118
			 | 
			
				120
			 | 
			
			
				     # append infobox 
			 | 
		
	
		
			
			| 
				119
			 | 
			
				121
			 | 
			
			
				     results.append({'infobox': infobox_title, 
			 | 
		
	
		
			
			| 
				120
			 | 
			
				122
			 | 
			
			
				                     'attributes': result_chunks, 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -122,7 +124,7 @@ def response(resp): 
			 | 
		
	
		
			
			| 
				122
			 | 
			
				124
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				123
			 | 
			
				125
			 | 
			
			
				     # append link to site 
			 | 
		
	
		
			
			| 
				124
			 | 
			
				126
			 | 
			
			
				     results.append({'url': resp.request.headers['Referer'].decode('utf8'), 
			 | 
		
	
		
			
			| 
				125
			 | 
			
				
			 | 
			
			
				-                    'title': infobox_title + ' - Wolfram|Alpha', 
			 | 
		
	
		
			
			| 
				126
			 | 
			
				
			 | 
			
			
				-                    'content': result}) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				127
			 | 
			
			
				+                    'title': title, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				128
			 | 
			
			
				+                    'content': result_content}) 
			 | 
		
	
		
			
			| 
				127
			 | 
			
				129
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				128
			 | 
			
				130
			 | 
			
			
				     return results 
			 |