From 5e224d3cdb67fa5c737355417886e3470d1181e9 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 29 Dec 2008 17:08:02 +0530 Subject: [PATCH] cache tpb search only for 24 hours --- README | 2 +- oxweb/thepiratebay.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README b/README index 166b37a..977b6a3 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ python-oxweb the internet is a dict Depends: python2.5 - python-oxutils + python-oxutils (bzr branch http//code.0xdb.org/python-oxutils) python-beautifulsoup (http://www.crummy.com/software/BeautifulSoup/) python-feedparser (http://www.feedparser.org/) (there seam to be some issues if not using the one from ubuntu/debian) diff --git a/oxweb/thepiratebay.py b/oxweb/thepiratebay.py index 85d7617..41c6252 100644 --- a/oxweb/thepiratebay.py +++ b/oxweb/thepiratebay.py @@ -13,6 +13,7 @@ import oxlib from torrent import Torrent +cache_timeout = 24*60*60 # cache search only for 24 hours season_episode = re.compile("S..E..", re.IGNORECASE) @@ -22,8 +23,8 @@ def _getUrl(url, data=None, headers=cache.DEFAULT_HEADERS, timeout=cache.cache_t headers['Cookie'] = 'language=en_EN' return cache.getUrl(url, data, headers, timeout) -def _getUrlUnicode(url): - return cache.getUrlUnicode(url, _getUrl=_getUrl) +def _getUrlUnicode(url, timeout=cache.cache_timeout): + return cache.getUrlUnicode(url, _getUrl=_getUrl, timeout=timeout) def findMovies(query, max_results=10): results = [] @@ -36,7 +37,7 @@ def findMovies(query, max_results=10): if not url.startswith('/'): url = "/" + url url = "http://thepiratebay.org" + url - data = _getUrlUnicode(url) + data = _getUrlUnicode(url, timeout=cache_timeout) regexp = '''(.*?).*?''' for row in re.compile(regexp, re.DOTALL).findall(data): torrentType = row[0]