on master help sign in
Merge branch 'master' of https://github.com/asciimoo/searx into filtron
commit26b85659c0b7c9bf545dfe4edeedc3ccf247bc97 authorMarkus Heiser <markus.heiser@darmarit.de> dateSun 15 Mar 2020, 09:19 (7 years ago) parent80f7b658e727ac
3 files changed+43−5
searx/templates/__common__/opensearch_response_rss.xml+24 searx/webapp.py+16−2 tests/unit/test_webapp.py+3−3
searx/templates/__common__/opensearch_response_rss.xml+24
@@ -25,5 +25,29 @@
2525 {% if r.pubdate %}<pubDate>{{ r.pubdate }}</pubDate>{% endif %}
2626 </item>
2727 {% endfor %}
28+ {% if answers %}
29+ {% for a in answers %}
30+ <item>
31+ <title>{{ a }}</title>
32+ <type>answer</type>
33+ </item>
34+ {% endfor %}
35+ {% endif %}
36+ {% if corrections %}
37+ {% for a in corrections %}
38+ <item>
39+ <title>{{ a }}</title>
40+ <type>correction</type>
41+ </item>
42+ {% endfor %}
43+ {% endif %}
44+ {% if suggestions %}
45+ {% for a in suggestions %}
46+ <item>
47+ <title>{{ a }}</title>
48+ <type>suggestion</type>
49+ </item>
50+ {% endfor %}
51+ {% endif %}
2852 </channel>
2953</rss>
searx/webapp.py+16−2
@@ -626,20 +626,34 @@ def index():
626626 mimetype='application/json')
627627 elif output_format == 'csv':
628628 csv = UnicodeWriter(StringIO())
629− keys = ('title', 'url', 'content', 'host', 'engine', 'score')
629+ keys = ('title', 'url', 'content', 'host', 'engine', 'score', 'type')
630630 csv.writerow(keys)
631631 for row in results:
632632 row['host'] = row['parsed_url'].netloc
633+ row['type'] = 'result'
634+ csv.writerow([row.get(key, '') for key in keys])
635+ for a in result_container.answers:
636+ row = {'title': a, 'type': 'answer'}
637+ csv.writerow([row.get(key, '') for key in keys])
638+ for a in result_container.suggestions:
639+ row = {'title': a, 'type': 'suggestion'}
640+ csv.writerow([row.get(key, '') for key in keys])
641+ for a in result_container.corrections:
642+ row = {'title': a, 'type': 'correction'}
633643 csv.writerow([row.get(key, '') for key in keys])
634644 csv.stream.seek(0)
635645 response = Response(csv.stream.read(), mimetype='application/csv')
636− cont_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search_query.query)
646+ cont_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search_query.query.decode('utf-8'))
637647 response.headers.add('Content-Disposition', cont_disp)
638648 return response
639649 elif output_format == 'rss':
650+ print(results)
640651 response_rss = render(
641652 'opensearch_response_rss.xml',
642653 results=results,
654+ answers=result_container.answers,
655+ corrections=result_container.corrections,
656+ suggestions=result_container.suggestions,
643657 q=request.form['q'],
644658 number_of_results=number_of_results,
645659 base_url=get_base_url(),
tests/unit/test_webapp.py+3−3
@@ -99,9 +99,9 @@ class ViewsTestCase(SearxTestCase):
9999 result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
100100
101101 self.assertEqual(
102− b'title,url,content,host,engine,score\r\n'
103− b'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,\r\n' # noqa
104− b'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,\r\n', # noqa
102+ b'title,url,content,host,engine,score,type\r\n'
103+ b'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,,result\r\n' # noqa
104+ b'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,,result\r\n', # noqa
105105 result.data
106106 )
107107