Pārlūkot izejas kodu

[fix] pep8 compatibility

Adam Tauber 10 gadus atpakaļ
vecāks
revīzija
b0fd71b7b3
2 mainītis faili ar 22 papildinājumiem un 18 dzēšanām
  1. 7
    6
      searx/engines/yahoo_news.py
  2. 15
    12
      searx/https_rewrite.py

+ 7
- 6
searx/engines/yahoo_news.py Parādīt failu

1
-## Yahoo (News)
2
-# 
1
+# Yahoo (News)
2
+#
3
 # @website     https://news.yahoo.com
3
 # @website     https://news.yahoo.com
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
 # @using-api   no (because pricing)
7
 # @using-api   no (because pricing)
7
 # @results     HTML (using search portal)
8
 # @results     HTML (using search portal)
8
 # @stable      no (HTML can change)
9
 # @stable      no (HTML can change)
22
 language_support = True
23
 language_support = True
23
 
24
 
24
 # search-url
25
 # search-url
25
-search_url = 'https://news.search.yahoo.com/search?{query}&b={offset}&fl=1&vl=lang_{lang}'
26
+search_url = 'https://news.search.yahoo.com/search?{query}&b={offset}&fl=1&vl=lang_{lang}'  # noqa
26
 
27
 
27
 # specific xpath variables
28
 # specific xpath variables
28
 results_xpath = '//div[@class="res"]'
29
 results_xpath = '//div[@class="res"]'
41
         language = 'en'
42
         language = 'en'
42
     else:
43
     else:
43
         language = params['language'].split('_')[0]
44
         language = params['language'].split('_')[0]
44
-    
45
+
45
     params['url'] = search_url.format(offset=offset,
46
     params['url'] = search_url.format(offset=offset,
46
                                       query=urlencode({'p': query}),
47
                                       query=urlencode({'p': query}),
47
                                       lang=language)
48
                                       lang=language)

+ 15
- 12
searx/https_rewrite.py Parādīt failu

45
     # get root node
45
     # get root node
46
     root = tree.getroot()
46
     root = tree.getroot()
47
 
47
 
48
-    #print(etree.tostring(tree))
49
-
50
     # check if root is a node with the name ruleset
48
     # check if root is a node with the name ruleset
51
     # TODO improve parsing
49
     # TODO improve parsing
52
-    if root.tag != 'ruleset':        
50
+    if root.tag != 'ruleset':
53
         return ()
51
         return ()
54
 
52
 
55
     # check if rule is deactivated by default
53
     # check if rule is deactivated by default
68
     for ruleset in root:
66
     for ruleset in root:
69
         # this child define a target
67
         # this child define a target
70
         if ruleset.tag == 'target':
68
         if ruleset.tag == 'target':
71
-            # check if required tags available 
69
+            # check if required tags available
72
             if not ruleset.attrib.get('host'):
70
             if not ruleset.attrib.get('host'):
73
                 continue
71
                 continue
74
 
72
 
75
             # convert host-rule to valid regex
73
             # convert host-rule to valid regex
76
-            host = ruleset.attrib.get('host').replace('.', '\.').replace('*', '.*')
74
+            host = ruleset.attrib.get('host')\
75
+                .replace('.', '\.').replace('*', '.*')
77
 
76
 
78
             # append to host list
77
             # append to host list
79
             hosts.append(host)
78
             hosts.append(host)
80
 
79
 
81
         # this child define a rule
80
         # this child define a rule
82
         elif ruleset.tag == 'rule':
81
         elif ruleset.tag == 'rule':
83
-            # check if required tags available 
82
+            # check if required tags available
84
             if not ruleset.attrib.get('from')\
83
             if not ruleset.attrib.get('from')\
85
                or not ruleset.attrib.get('to'):
84
                or not ruleset.attrib.get('to'):
86
                 continue
85
                 continue
87
 
86
 
88
-            # TODO hack, which convert a javascript regex group into a valid python regex group
87
+            # TODO hack, which convert a javascript regex group
88
+            # into a valid python regex group
89
             rule_from = ruleset.attrib.get('from').replace('$', '\\')
89
             rule_from = ruleset.attrib.get('from').replace('$', '\\')
90
             rule_to = ruleset.attrib.get('to').replace('$', '\\')
90
             rule_to = ruleset.attrib.get('to').replace('$', '\\')
91
 
91
 
92
-            # TODO, not working yet because of the hack above, currently doing that in webapp.py
93
-            #rule_from_rgx = re.compile(rule_from, re.I)
92
+            # TODO, not working yet because of the hack above,
93
+            # currently doing that in webapp.py
94
+            # rule_from_rgx = re.compile(rule_from, re.I)
94
 
95
 
95
             # append rule
96
             # append rule
96
             rules.append((rule_from, rule_to))
97
             rules.append((rule_from, rule_to))
97
 
98
 
98
         # this child define an exclusion
99
         # this child define an exclusion
99
         elif ruleset.tag == 'exclusion':
100
         elif ruleset.tag == 'exclusion':
100
-            # check if required tags available 
101
+            # check if required tags available
101
             if not ruleset.attrib.get('pattern'):
102
             if not ruleset.attrib.get('pattern'):
102
                 continue
103
                 continue
103
 
104
 
124
         rules_path += '/'
125
         rules_path += '/'
125
 
126
 
126
     # search all xml files which are stored in the https rule directory
127
     # search all xml files which are stored in the https rule directory
127
-    xml_files = [ join(rules_path,f) for f in listdir(rules_path) if isfile(join(rules_path,f)) and f[-4:] == '.xml' ]
128
+    xml_files = [join(rules_path, f)
129
+                 for f in listdir(rules_path)
130
+                 if isfile(join(rules_path, f)) and f[-4:] == '.xml']
128
 
131
 
129
     # load xml-files
132
     # load xml-files
130
     for ruleset_file in xml_files:
133
     for ruleset_file in xml_files:
137
 
140
 
138
         # append ruleset
141
         # append ruleset
139
         https_rules.append(ruleset)
142
         https_rules.append(ruleset)
140
-        
143
+
141
     print(' * {n} https-rules loaded'.format(n=len(https_rules)))
144
     print(' * {n} https-rules loaded'.format(n=len(https_rules)))