add time range search for google

This commit is contained in:
Noemi Vanyi 2016-07-18 16:09:18 +02:00
parent 713d30400b
commit 2e5839503f
1 changed files with 8 additions and 0 deletions

View File

@ -24,6 +24,7 @@ categories = ['general']
paging = True paging = True
language_support = True language_support = True
use_locale_domain = True use_locale_domain = True
time_range_support = True
# based on https://en.wikipedia.org/wiki/List_of_Google_domains and tests # based on https://en.wikipedia.org/wiki/List_of_Google_domains and tests
default_hostname = 'www.google.com' default_hostname = 'www.google.com'
@ -92,6 +93,11 @@ search_url = ('https://{hostname}' +
search_path + search_path +
'?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&ei=x') '?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&ei=x')
time_range_search = "&tbs=qdr:{range}"
time_range_dict = {'day': 'd',
'week': 'w',
'month': 'm'}
# other URLs # other URLs
map_hostname_start = 'maps.google.' map_hostname_start = 'maps.google.'
maps_path = '/maps' maps_path = '/maps'
@ -179,6 +185,8 @@ def request(query, params):
query=urlencode({'q': query}), query=urlencode({'q': query}),
hostname=google_hostname, hostname=google_hostname,
lang=url_lang) lang=url_lang)
if params['time_range']:
params['url'] += time_range_search.format(range=time_range_dict[params['time_range']])
params['headers']['Accept-Language'] = language params['headers']['Accept-Language'] = language
params['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' params['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'