Преглед на файлове

[fix] pep8 : engines (errors E121, E127, E128 and E501 still exist)

dalf преди 10 години
родител
ревизия
7c13d630e4

+ 8
- 7
searx/engines/bing.py Целия файл

@@ -1,8 +1,9 @@
1 1
 ## Bing (Web)
2
-# 
2
+#
3 3
 # @website     https://www.bing.com
4
-# @provide-api yes (http://datamarket.azure.com/dataset/bing/search), max. 5000 query/month
5
-# 
4
+# @provide-api yes (http://datamarket.azure.com/dataset/bing/search),
5
+#              max. 5000 query/month
6
+#
6 7
 # @using-api   no (because of query limit)
7 8
 # @results     HTML (using search portal)
8 9
 # @stable      no (HTML can change)
@@ -58,8 +59,8 @@ def response(resp):
58 59
         content = escape(' '.join(result.xpath('.//p//text()')))
59 60
 
60 61
         # append result
61
-        results.append({'url': url, 
62
-                        'title': title, 
62
+        results.append({'url': url,
63
+                        'title': title,
63 64
                         'content': content})
64 65
 
65 66
     # return results if something is found
@@ -74,8 +75,8 @@ def response(resp):
74 75
         content = escape(' '.join(result.xpath('.//p//text()')))
75 76
 
76 77
         # append result
77
-        results.append({'url': url, 
78
-                        'title': title, 
78
+        results.append({'url': url,
79
+                        'title': title,
79 80
                         'content': content})
80 81
 
81 82
     # return results

+ 11
- 9
searx/engines/bing_images.py Целия файл

@@ -1,17 +1,19 @@
1 1
 ## Bing (Images)
2
-# 
2
+#
3 3
 # @website     https://www.bing.com/images
4
-# @provide-api yes (http://datamarket.azure.com/dataset/bing/search), max. 5000 query/month
5
-# 
4
+# @provide-api yes (http://datamarket.azure.com/dataset/bing/search),
5
+#              max. 5000 query/month
6
+#
6 7
 # @using-api   no (because of query limit)
7 8
 # @results     HTML (using search portal)
8 9
 # @stable      no (HTML can change)
9 10
 # @parse       url, title, img_src
10 11
 #
11
-# @todo        currently there are up to 35 images receive per page, because bing does not parse count=10. limited response to 10 images
12
+# @todo        currently there are up to 35 images receive per page,
13
+#              because bing does not parse count=10.
14
+#              limited response to 10 images
12 15
 
13 16
 from urllib import urlencode
14
-from cgi import escape
15 17
 from lxml import html
16 18
 from yaml import load
17 19
 import re
@@ -51,15 +53,15 @@ def response(resp):
51 53
     dom = html.fromstring(resp.content)
52 54
 
53 55
     # init regex for yaml-parsing
54
-    p = re.compile( '({|,)([a-z]+):(")')
56
+    p = re.compile('({|,)([a-z]+):(")')
55 57
 
56 58
     # parse results
57 59
     for result in dom.xpath('//div[@class="dg_u"]'):
58 60
         link = result.xpath('./a')[0]
59 61
 
60 62
         # parse yaml-data (it is required to add a space, to make it parsable)
61
-        yaml_data = load(p.sub( r'\1\2: \3', link.attrib.get('m')))
62
- 
63
+        yaml_data = load(p.sub(r'\1\2: \3', link.attrib.get('m')))
64
+
63 65
         title = link.attrib.get('t1')
64 66
         #url = 'http://' + link.attrib.get('t3')
65 67
         url = yaml_data.get('surl')
@@ -69,7 +71,7 @@ def response(resp):
69 71
         results.append({'template': 'images.html',
70 72
                         'url': url,
71 73
                         'title': title,
72
-                        'content': '',  
74
+                        'content': '',
73 75
                         'img_src': img_src})
74 76
 
75 77
         # TODO stop parsing if 10 images are found

+ 10
- 9
searx/engines/bing_news.py Целия файл

@@ -1,8 +1,9 @@
1 1
 ## Bing (News)
2
-# 
2
+#
3 3
 # @website     https://www.bing.com/news
4
-# @provide-api yes (http://datamarket.azure.com/dataset/bing/search), max. 5000 query/month
5
-# 
4
+# @provide-api yes (http://datamarket.azure.com/dataset/bing/search),
5
+#              max. 5000 query/month
6
+#
6 7
 # @using-api   no (because of query limit)
7 8
 # @results     HTML (using search portal)
8 9
 # @stable      no (HTML can change)
@@ -57,12 +58,12 @@ def response(resp):
57 58
         url = link.attrib.get('href')
58 59
         title = ' '.join(link.xpath('.//text()'))
59 60
         contentXPath = result.xpath('.//div[@class="sn_txt"]/div//span[@class="sn_snip"]//text()')
60
-        if contentXPath != None:
61
+        if contentXPath is not None:
61 62
             content = escape(' '.join(contentXPath))
62
-            
63
+
63 64
         # parse publishedDate
64 65
         publishedDateXPath = result.xpath('.//div[@class="sn_txt"]/div//span[contains(@class,"sn_ST")]//span[contains(@class,"sn_tm")]//text()')
65
-        if publishedDateXPath != None:
66
+        if publishedDateXPath is not None:
66 67
             publishedDate = escape(' '.join(publishedDateXPath))
67 68
 
68 69
         if re.match("^[0-9]+ minute(s|) ago$", publishedDate):
@@ -89,10 +90,10 @@ def response(resp):
89 90
             except TypeError:
90 91
                 # FIXME
91 92
                 publishedDate = datetime.now()
92
-                
93
+
93 94
         # append result
94
-        results.append({'url': url, 
95
-                        'title': title, 
95
+        results.append({'url': url,
96
+                        'title': title,
96 97
                         'publishedDate': publishedDate,
97 98
                         'content': content})
98 99
 

+ 1
- 1
searx/engines/currency_convert.py Целия файл

@@ -55,6 +55,6 @@ def response(resp):
55 55
         resp.search_params['to'].lower()
56 56
     )
57 57
 
58
-    results.append({'answer' : answer, 'url': url})
58
+    results.append({'answer': answer, 'url': url})
59 59
 
60 60
     return results

+ 2
- 3
searx/engines/dailymotion.py Целия файл

@@ -1,8 +1,8 @@
1 1
 ## Dailymotion (Videos)
2
-# 
2
+#
3 3
 # @website     https://www.dailymotion.com
4 4
 # @provide-api yes (http://www.dailymotion.com/developer)
5
-# 
5
+#
6 6
 # @using-api   yes
7 7
 # @results     JSON
8 8
 # @stable      yes
@@ -12,7 +12,6 @@
12 12
 
13 13
 from urllib import urlencode
14 14
 from json import loads
15
-from lxml import html
16 15
 
17 16
 # engine dependent config
18 17
 categories = ['videos']

+ 2
- 2
searx/engines/deviantart.py Целия файл

@@ -1,8 +1,8 @@
1 1
 ## Deviantart (Images)
2
-# 
2
+#
3 3
 # @website     https://www.deviantart.com/
4 4
 # @provide-api yes (https://www.deviantart.com/developers/) (RSS)
5
-# 
5
+#
6 6
 # @using-api   no (TODO, rewrite to api)
7 7
 # @results     HTML
8 8
 # @stable      no (HTML can change)

+ 7
- 5
searx/engines/duckduckgo.py Целия файл

@@ -1,15 +1,17 @@
1 1
 ## DuckDuckGo (Web)
2
-# 
2
+#
3 3
 # @website     https://duckduckgo.com/
4
-# @provide-api yes (https://duckduckgo.com/api), but not all results from search-site
5
-# 
4
+# @provide-api yes (https://duckduckgo.com/api),
5
+#              but not all results from search-site
6
+#
6 7
 # @using-api   no
7 8
 # @results     HTML (using search portal)
8 9
 # @stable      no (HTML can change)
9 10
 # @parse       url, title, content
10 11
 #
11 12
 # @todo        rewrite to api
12
-# @todo        language support (the current used site does not support language-change)
13
+# @todo        language support
14
+#              (the current used site does not support language-change)
13 15
 
14 16
 from urllib import urlencode
15 17
 from lxml.html import fromstring
@@ -37,7 +39,7 @@ def request(query, params):
37 39
     if params['language'] == 'all':
38 40
         locale = 'en-us'
39 41
     else:
40
-        locale = params['language'].replace('_','-').lower()
42
+        locale = params['language'].replace('_', '-').lower()
41 43
 
42 44
     params['url'] = url.format(
43 45
         query=urlencode({'q': query, 'kl': locale}),

+ 1
- 1
searx/engines/dummy.py Целия файл

@@ -1,5 +1,5 @@
1 1
 ## Dummy
2
-# 
2
+#
3 3
 # @results     empty array
4 4
 # @stable      yes
5 5
 

+ 6
- 5
searx/engines/faroo.py Целия файл

@@ -1,8 +1,8 @@
1 1
 ## Faroo (Web, News)
2
-# 
2
+#
3 3
 # @website     http://www.faroo.com
4 4
 # @provide-api yes (http://www.faroo.com/hp/api/api.html), require API-key
5
-# 
5
+#
6 6
 # @using-api   yes
7 7
 # @results     JSON
8 8
 # @stable      yes
@@ -24,9 +24,10 @@ api_key = None
24 24
 url = 'http://www.faroo.com/'
25 25
 search_url = url + 'api?{query}&start={offset}&length={number_of_results}&l={language}&src={categorie}&i=false&f=json&key={api_key}'
26 26
 
27
-search_category = {'general': 'web',                
27
+search_category = {'general': 'web',
28 28
                 'news': 'news'}
29 29
 
30
+
30 31
 # do search-request
31 32
 def request(query, params):
32 33
     offset = (params['pageno']-1) * number_of_results + 1
@@ -48,7 +49,7 @@ def request(query, params):
48 49
                                       query=urlencode({'q': query}),
49 50
                                       language=language,
50 51
                                       categorie=categorie,
51
-                                      api_key=api_key )
52
+                                      api_key=api_key)
52 53
 
53 54
     # using searx User-Agent
54 55
     params['headers']['User-Agent'] = searx_useragent()
@@ -101,7 +102,7 @@ def response(resp):
101 102
             results.append({'template': 'images.html',
102 103
                             'url': result['url'],
103 104
                             'title': result['title'],
104
-                            'content': result['kwic'],  
105
+                            'content': result['kwic'],
105 106
                             'img_src': result['iurl']})
106 107
 
107 108
     # return results

+ 2
- 2
searx/engines/generalfile.py Целия файл

@@ -1,8 +1,8 @@
1 1
 ## General Files (Files)
2
-# 
2
+#
3 3
 # @website     http://www.general-files.org
4 4
 # @provide-api no (nothing found)
5
-# 
5
+#
6 6
 # @using-api   no (because nothing found)
7 7
 # @results     HTML (using search portal)
8 8
 # @stable      no (HTML can change)

+ 2
- 2
searx/engines/github.py Целия файл

@@ -1,8 +1,8 @@
1 1
 ## Github (It)
2
-# 
2
+#
3 3
 # @website     https://github.com/
4 4
 # @provide-api yes (https://developer.github.com/v3/)
5
-# 
5
+#
6 6
 # @using-api   yes
7 7
 # @results     JSON
8 8
 # @stable      yes (using api)

+ 4
- 3
searx/engines/google_images.py Целия файл

@@ -1,8 +1,9 @@
1 1
 ## Google (Images)
2
-# 
2
+#
3 3
 # @website     https://www.google.com
4
-# @provide-api yes (https://developers.google.com/web-search/docs/), deprecated!
5
-# 
4
+# @provide-api yes (https://developers.google.com/web-search/docs/),
5
+#              deprecated!
6
+#
6 7
 # @using-api   yes
7 8
 # @results     JSON
8 9
 # @stable      yes (but deprecated)

+ 4
- 3
searx/engines/google_news.py Целия файл

@@ -1,8 +1,9 @@
1 1
 ## Google (News)
2
-# 
2
+#
3 3
 # @website     https://www.google.com
4
-# @provide-api yes (https://developers.google.com/web-search/docs/), deprecated!
5
-# 
4
+# @provide-api yes (https://developers.google.com/web-search/docs/),
5
+#              deprecated!
6
+#
6 7
 # @using-api   yes
7 8
 # @results     JSON
8 9
 # @stable      yes (but deprecated)

+ 15
- 15
searx/engines/openstreetmap.py Целия файл

@@ -39,16 +39,16 @@ def response(resp):
39 39
         url = result_base_url.format(osm_type=osm_type,
40 40
                                      osm_id=r['osm_id'])
41 41
 
42
-        osm = {'type':osm_type,
43
-               'id':r['osm_id']}
42
+        osm = {'type': osm_type,
43
+               'id': r['osm_id']}
44 44
 
45
-        geojson =  r.get('geojson')
45
+        geojson = r.get('geojson')
46 46
 
47 47
         # if no geojson is found and osm_type is a node, add geojson Point
48 48
         if not geojson and\
49 49
            osm_type == 'node':
50
-            geojson = {u'type':u'Point', 
51
-                       u'coordinates':[r['lon'],r['lat']]}
50
+            geojson = {u'type': u'Point',
51
+                       u'coordinates': [r['lon'], r['lat']]}
52 52
 
53 53
         address_raw = r.get('address')
54 54
         address = {}
@@ -59,20 +59,20 @@ def response(resp):
59 59
            r['class'] == 'tourism' or\
60 60
            r['class'] == 'leisure':
61 61
             if address_raw.get('address29'):
62
-                address = {'name':address_raw.get('address29')}
62
+                address = {'name': address_raw.get('address29')}
63 63
             else:
64
-                address = {'name':address_raw.get(r['type'])}
64
+                address = {'name': address_raw.get(r['type'])}
65 65
 
66 66
         # add rest of adressdata, if something is already found
67 67
         if address.get('name'):
68
-            address.update({'house_number':address_raw.get('house_number'),
69
-                       'road':address_raw.get('road'),
70
-                       'locality':address_raw.get('city',
71
-                                  address_raw.get('town', 
72
-                                  address_raw.get('village'))),
73
-                       'postcode':address_raw.get('postcode'),
74
-                       'country':address_raw.get('country'),
75
-                       'country_code':address_raw.get('country_code')})
68
+            address.update({'house_number': address_raw.get('house_number'),
69
+                           'road': address_raw.get('road'),
70
+                           'locality': address_raw.get('city',
71
+                                       address_raw.get('town',
72
+                                       address_raw.get('village'))),
73
+                           'postcode': address_raw.get('postcode'),
74
+                           'country': address_raw.get('country'),
75
+                           'country_code': address_raw.get('country_code')})
76 76
         else:
77 77
             address = None
78 78
 

+ 3
- 3
searx/engines/piratebay.py Целия файл

@@ -1,8 +1,8 @@
1 1
 ## Piratebay (Videos, Music, Files)
2
-# 
2
+#
3 3
 # @website     https://thepiratebay.se
4 4
 # @provide-api no (nothing found)
5
-# 
5
+#
6 6
 # @using-api   no
7 7
 # @results     HTML (using search portal)
8 8
 # @stable      yes (HTML can change)
@@ -23,7 +23,7 @@ url = 'https://thepiratebay.se/'
23 23
 search_url = url + 'search/{search_term}/{pageno}/99/{search_type}'
24 24
 
25 25
 # piratebay specific type-definitions
26
-search_types = {'files': '0',                
26
+search_types = {'files': '0',
27 27
                 'music': '100',
28 28
                 'videos': '200'}
29 29
 

+ 2
- 2
searx/engines/soundcloud.py Целия файл

@@ -1,8 +1,8 @@
1 1
 ## Soundcloud (Music)
2
-# 
2
+#
3 3
 # @website     https://soundcloud.com
4 4
 # @provide-api yes (https://developers.soundcloud.com/)
5
-# 
5
+#
6 6
 # @using-api   yes
7 7
 # @results     JSON
8 8
 # @stable      yes

+ 4
- 4
searx/engines/stackoverflow.py Целия файл

@@ -1,8 +1,8 @@
1 1
 ## Stackoverflow (It)
2
-# 
2
+#
3 3
 # @website     https://stackoverflow.com/
4 4
 # @provide-api not clear (https://api.stackexchange.com/docs/advanced-search)
5
-# 
5
+#
6 6
 # @using-api   no
7 7
 # @results     HTML
8 8
 # @stable      no (HTML can change)
@@ -50,8 +50,8 @@ def response(resp):
50 50
         content = escape(' '.join(result.xpath(content_xpath)))
51 51
 
52 52
         # append result
53
-        results.append({'url': href, 
54
-                        'title': title, 
53
+        results.append({'url': href,
54
+                        'title': title,
55 55
                         'content': content})
56 56
 
57 57
     # return results

+ 2
- 2
searx/engines/twitter.py Целия файл

@@ -1,8 +1,8 @@
1 1
 ## Twitter (Social media)
2
-# 
2
+#
3 3
 # @website     https://www.bing.com/news
4 4
 # @provide-api yes (https://dev.twitter.com/docs/using-search)
5
-# 
5
+#
6 6
 # @using-api   no
7 7
 # @results     HTML (using search portal)
8 8
 # @stable      no (HTML can change)

+ 7
- 5
searx/engines/vimeo.py Целия файл

@@ -1,8 +1,9 @@
1 1
 ## Vimeo (Videos)
2
-# 
2
+#
3 3
 # @website     https://vimeo.com/
4
-# @provide-api yes (http://developer.vimeo.com/api), they have a maximum count of queries/hour
5
-# 
4
+# @provide-api yes (http://developer.vimeo.com/api),
5
+#              they have a maximum count of queries/hour
6
+#
6 7
 # @using-api   no (TODO, rewrite to api)
7 8
 # @results     HTML (using search portal)
8 9
 # @stable      no (HTML can change)
@@ -35,11 +36,12 @@ publishedDate_xpath = './/p[@class="meta"]//attribute::datetime'
35 36
 
36 37
 # do search-request
37 38
 def request(query, params):
38
-    params['url'] = search_url.format(pageno=params['pageno'] ,
39
+    params['url'] = search_url.format(pageno=params['pageno'],
39 40
                                       query=urlencode({'q': query}))
40 41
 
41 42
     # TODO required?
42
-    params['cookies']['__utma'] = '00000000.000#0000000.0000000000.0000000000.0000000000.0'
43
+    params['cookies']['__utma'] =\
44
+        '00000000.000#0000000.0000000000.0000000000.0000000000.0'
43 45
 
44 46
     return params
45 47
 

+ 6
- 5
searx/engines/yacy.py Целия файл

@@ -1,8 +1,9 @@
1 1
 ## Yacy (Web, Images, Videos, Music, Files)
2
-# 
2
+#
3 3
 # @website     http://yacy.net
4
-# @provide-api yes (http://www.yacy-websuche.de/wiki/index.php/Dev:APIyacysearch)
5
-# 
4
+# @provide-api yes
5
+#              (http://www.yacy-websuche.de/wiki/index.php/Dev:APIyacysearch)
6
+#
6 7
 # @using-api   yes
7 8
 # @results     JSON
8 9
 # @stable      yes
@@ -16,7 +17,7 @@ from urllib import urlencode
16 17
 from dateutil import parser
17 18
 
18 19
 # engine dependent config
19
-categories = ['general', 'images'] #TODO , 'music', 'videos', 'files'
20
+categories = ['general', 'images']  # TODO , 'music', 'videos', 'files'
20 21
 paging = True
21 22
 language_support = True
22 23
 number_of_results = 5
@@ -28,7 +29,7 @@ search_url = '/yacysearch.json?{query}&startRecord={offset}&maximumRecords={limi
28 29
 # yacy specific type-definitions
29 30
 search_types = {'general': 'text',
30 31
                 'images': 'image',
31
-                'files': 'app',               
32
+                'files': 'app',
32 33
                 'music': 'audio',
33 34
                 'videos': 'video'}
34 35
 

+ 8
- 7
searx/engines/yahoo.py Целия файл

@@ -1,8 +1,9 @@
1 1
 ## Yahoo (Web)
2
-# 
2
+#
3 3
 # @website     https://search.yahoo.com/web
4
-# @provide-api yes (https://developer.yahoo.com/boss/search/), $0.80/1000 queries
5
-# 
4
+# @provide-api yes (https://developer.yahoo.com/boss/search/),
5
+#              $0.80/1000 queries
6
+#
6 7
 # @using-api   no (because pricing)
7 8
 # @results     HTML (using search portal)
8 9
 # @stable      no (HTML can change)
@@ -40,8 +41,8 @@ def parse_url(url_string):
40 41
         if endpos > -1:
41 42
             endpositions.append(endpos)
42 43
 
43
-    if start==0 or len(endpositions) == 0:
44
-        return url_string        
44
+    if start == 0 or len(endpositions) == 0:
45
+        return url_string
45 46
     else:
46 47
         end = min(endpositions)
47 48
         return unquote(url_string[start:end])
@@ -84,8 +85,8 @@ def response(resp):
84 85
         content = extract_text(result.xpath(content_xpath)[0])
85 86
 
86 87
         # append result
87
-        results.append({'url': url, 
88
-                        'title': title, 
88
+        results.append({'url': url,
89
+                        'title': title,
89 90
                         'content': content})
90 91
 
91 92
     # if no suggestion found, return results

+ 2
- 2
searx/engines/youtube.py Целия файл

@@ -1,8 +1,8 @@
1 1
 ## Youtube (Videos)
2
-# 
2
+#
3 3
 # @website     https://www.youtube.com/
4 4
 # @provide-api yes (http://gdata-samples-youtube-search-py.appspot.com/)
5
-# 
5
+#
6 6
 # @using-api   yes
7 7
 # @results     JSON
8 8
 # @stable      yes