Kaynağa Gözat

Add searx user agent to Reddit engine request to comply with API usage terms

Kirill Isakov 9 yıl önce
ebeveyn
işleme
d0001f10e6
2 değiştirilmiş dosya ile 6 ekleme ve 0 silme
  1. 4
    0
      searx/engines/reddit.py
  2. 2
    0
      tests/unit/engines/test_reddit.py

+ 4
- 0
searx/engines/reddit.py Dosyayı Görüntüle

@@ -15,6 +15,7 @@ from cgi import escape
15 15
 from urllib import urlencode
16 16
 from urlparse import urlparse
17 17
 from datetime import datetime
18
+from searx.utils import searx_useragent
18 19
 
19 20
 # engine dependent config
20 21
 categories = ['general', 'images', 'news', 'social media']
@@ -30,6 +31,9 @@ def request(query, params):
30 31
                        'limit': page_size})
31 32
     params['url'] = search_url.format(query=query)
32 33
 
34
+    # using searx User-Agent
35
+    params['headers']['User-Agent'] = searx_useragent()
36
+
33 37
     return params
34 38
 
35 39
 

+ 2
- 0
tests/unit/engines/test_reddit.py Dosyayı Görüntüle

@@ -3,6 +3,7 @@ import mock
3 3
 from searx.engines import reddit
4 4
 from searx.testing import SearxTestCase
5 5
 from datetime import datetime
6
+from searx.utils import searx_useragent
6 7
 
7 8
 
8 9
 class TestRedditEngine(SearxTestCase):
@@ -14,6 +15,7 @@ class TestRedditEngine(SearxTestCase):
14 15
         self.assertTrue('url' in params)
15 16
         self.assertTrue(query in params['url'])
16 17
         self.assertTrue('reddit.com' in params['url'])
18
+        self.assertEqual(params['headers']['User-Agent'], searx_useragent())
17 19
 
18 20
     def test_response(self):
19 21
         resp = mock.Mock(text='{}')