Browse Source

[enh] sort piratebay results by seeders

rhapsodhy 11 years ago
parent
commit
6725112e6b
1 changed files with 7 additions and 2 deletions
  1. 7 2
      searx/engines/piratebay.py

+ 7 - 2
searx/engines/piratebay.py

@@ -24,7 +24,6 @@ def request(query, params):
                                       pageno=params['pageno'] - 1)
                                       pageno=params['pageno'] - 1)
     return params
     return params
 
 
-
 def response(resp):
 def response(resp):
     results = []
     results = []
     dom = html.fromstring(resp.text)
     dom = html.fromstring(resp.text)
@@ -45,4 +44,10 @@ def response(resp):
                         'leech': leech,
                         'leech': leech,
                         'magnetlink': magnetlink.attrib['href'],
                         'magnetlink': magnetlink.attrib['href'],
                         'template': 'torrent.html'})
                         'template': 'torrent.html'})
-    return results
+        return sorted(results, key=lambda x: get_int('seed'), reversed=True)
+
+def get_int(field):
+    try:
+        return int(field)
+    except TypeError:
+        return 0