Przeglądaj źródła

Merge pull request #65 from rsdy/master

[enh] sort piratebay results by seeders
Adam Tauber 11 lat temu
rodzic
commit
637d58f2ed
1 zmienionych plików z 7 dodań i 2 usunięć
  1. 7
    2
      searx/engines/piratebay.py

+ 7
- 2
searx/engines/piratebay.py Wyświetl plik

@@ -24,7 +24,6 @@ def request(query, params):
24 24
                                       pageno=params['pageno'] - 1)
25 25
     return params
26 26
 
27
-
28 27
 def response(resp):
29 28
     results = []
30 29
     dom = html.fromstring(resp.text)
@@ -45,4 +44,10 @@ def response(resp):
45 44
                         'leech': leech,
46 45
                         'magnetlink': magnetlink.attrib['href'],
47 46
                         'template': 'torrent.html'})
48
-    return results
47
+        return sorted(results, key=lambda x: get_int('seed'), reversed=True)
48
+
49
+def get_int(field):
50
+    try:
51
+        return int(field)
52
+    except TypeError:
53
+        return 0