Selaa lähdekoodia

add time range search for google

Noemi Vanyi 8 vuotta sitten
vanhempi
commit
2e5839503f
1 muutettua tiedostoa jossa 8 lisäystä ja 0 poistoa
  1. 8
    0
      searx/engines/google.py

+ 8
- 0
searx/engines/google.py Näytä tiedosto

@@ -24,6 +24,7 @@ categories = ['general']
24 24
 paging = True
25 25
 language_support = True
26 26
 use_locale_domain = True
27
+time_range_support = True
27 28
 
28 29
 # based on https://en.wikipedia.org/wiki/List_of_Google_domains and tests
29 30
 default_hostname = 'www.google.com'
@@ -92,6 +93,11 @@ search_url = ('https://{hostname}' +
92 93
               search_path +
93 94
               '?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&ei=x')
94 95
 
96
+time_range_search = "&tbs=qdr:{range}"
97
+time_range_dict = {'day': 'd',
98
+                   'week': 'w',
99
+                   'month': 'm'}
100
+
95 101
 # other URLs
96 102
 map_hostname_start = 'maps.google.'
97 103
 maps_path = '/maps'
@@ -179,6 +185,8 @@ def request(query, params):
179 185
                                       query=urlencode({'q': query}),
180 186
                                       hostname=google_hostname,
181 187
                                       lang=url_lang)
188
+    if params['time_range']:
189
+        params['url'] += time_range_search.format(range=time_range_dict[params['time_range']])
182 190
 
183 191
     params['headers']['Accept-Language'] = language
184 192
     params['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'