From ee44a01b7606ad7e16a013a44fc7e5fab0b3c426 Mon Sep 17 00:00:00 2001 From: TheLegs Date: Wed, 4 Dec 2013 00:53:01 +0100 Subject: [PATCH] Beautify output from TorrentReactor The data for starts with a pretty long category in square brackets (eg. [Movies - DVD-R]) which makes the title uneasy to read in the results window. Also, added rev sorting by seeds. --- resources/lib/search.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/lib/search.py b/resources/lib/search.py index 6ab67e2..b67123e 100644 --- a/resources/lib/search.py +++ b/resources/lib/search.py @@ -1,8 +1,10 @@ import re import socket from urllib2 import urlopen +from operator import itemgetter from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup + socket.setdefaulttimeout(15) class Search: @@ -60,12 +62,14 @@ class TorrentReactor(Search): soup = BeautifulStoneSoup(f.read()) for item in soup.findAll('item'): (seeds, leechers) = re.findall('Status: (\d+) seeders, (\d+) leecher', item.description.text)[0] + title = re.findall(r'\[(?:[^\]])*\] (.*)', item.title.text)[0] torrents.append({ 'url': item.enclosure['url'], - 'name': item.title.text, + 'name': title, 'seeds': int(seeds), 'leechers': int(leechers), }) + torrents = sorted(torrents, key=itemgetter('seeds'), reverse=True) return torrents if __name__ == '__main__':