From 931faab5920edb4493ce68e421f22ee4c808b075 Mon Sep 17 00:00:00 2001 From: DrFrasierCrane Date: Sun, 6 Jan 2008 16:47:07 +0100 Subject: [PATCH] =?utf8?q?=3D=3Futf-8=3Fq=3FBug=3D20497629=3D20=3DE2=3D80?= =?utf8?q?=3D93=3D20Work=3D20for=3D20local=3D20file=3D20feeds.?= --- straw/FeedUpdater.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/straw/FeedUpdater.py b/straw/FeedUpdater.py index 5a44979..2b0a605 100644 --- a/straw/FeedUpdater.py +++ b/straw/FeedUpdater.py @@ -18,8 +18,11 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """ from JobManager import Job, TaskResult, TaskThread, TaskInfo, ThreadPoolJobHandler -import FeedManager +import Config import JobManager +import httplib2 +import os +import urlparse class FeedUpdateJobHandler(ThreadPoolJobHandler): job_id = "feed-update" @@ -40,7 +43,7 @@ class FeedUpdateJobHandler(ThreadPoolJobHandler): def _prepare_result(self): list = [] - + while not self.result_queue.empty(): list.append(self.result_queue.get()) @@ -58,17 +61,29 @@ class FeedUpdateTaskThread(TaskThread): def __init__(self, handler, task_queue, result_queue): TaskThread.__init__(self, handler, task_queue, result_queue) + def _get_feed_content(self, url): + schema = urlparse.urlsplit(url, "http")[0] + content = None + + if schema == "http": + CACHE_DIR = os.path.join(Config.straw_home(), 'cache') + h = httplib2.Http(CACHE_DIR) + content = h.request(url, "GET")[1] + elif schema == "file": + try: + f = open(url[len("file://"):], "r") + content = f.read() + f.close() + except Exception: + # TODO: error reporting! + pass + + return content + def _process(self, task): - import httplib2 feed = task.data["feed"] - import os - from straw import Config - CACHE_DIR = os.path.join(Config.straw_home(), 'cache') - h = httplib2.Http(CACHE_DIR) - #httplib2.debuglevel=4 - url = feed.location#feed.location - resp, content = h.request(url, "GET") + content = self._get_feed_content(feed.location) import SummaryParser parsed = SummaryParser.parse(content, feed) -- 2.11.4.GIT