|
@@ -11,8 +11,6 @@
|
11
|
11
|
@parse url, title, content
|
12
|
12
|
|
13
|
13
|
@todo rewrite to api
|
14
|
|
- @todo language support
|
15
|
|
- (the current used site does not support language-change)
|
16
|
14
|
"""
|
17
|
15
|
|
18
|
16
|
from urllib import urlencode
|
|
@@ -39,13 +37,22 @@ def request(query, params):
|
39
|
37
|
offset = (params['pageno'] - 1) * 30
|
40
|
38
|
|
41
|
39
|
if params['language'] == 'all':
|
42
|
|
- locale = 'en-us'
|
|
40
|
+ locale = None
|
43
|
41
|
else:
|
44
|
|
- locale = params['language'].replace('_', '-').lower()
|
45
|
|
-
|
46
|
|
- params['url'] = url.format(
|
47
|
|
- query=urlencode({'q': query, 'kl': locale}),
|
48
|
|
- offset=offset)
|
|
42
|
+ locale = params['language'].split('_')
|
|
43
|
+ if len(locale) == 2:
|
|
44
|
+ # country code goes first
|
|
45
|
+ locale = locale[1].lower() + '-' + locale[0].lower()
|
|
46
|
+ else:
|
|
47
|
+ # doesn't actually do anything because ddg requires both country and language
|
|
48
|
+ locale = locale[0].lower()
|
|
49
|
+
|
|
50
|
+ if locale:
|
|
51
|
+ params['url'] = url.format(
|
|
52
|
+ query=urlencode({'q': query, 'kl': locale}), offset=offset)
|
|
53
|
+ else:
|
|
54
|
+ params['url'] = url.format(
|
|
55
|
+ query=urlencode({'q': query}), offset=offset)
|
49
|
56
|
|
50
|
57
|
return params
|
51
|
58
|
|