Implemented "mark all as read".
[straw.git] / straw / FeedDiscovery.py
blobd1fd078a11ee1063aa833a50a8e658ce227586cb
1 """
3 """
5 __copyright__ = "Copyright (c) 2002-2005 Free Software Foundation, Inc."
6 __license__ = """
7 Straw is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 2 of the License, or (at your option) any later
10 version.
12 Straw is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 Place - Suite 330, Boston, MA 02111-1307, USA. """
20 from JobManager import Job, TaskResult, TaskThread, JobHandler
21 import Fetcher
22 import JobManager
23 import SummaryParser
24 import feedfinder
25 import gobject
27 class FeedDiscoveryJobHandler(JobHandler):
28 job_id = "feed-discovery"
30 __gsignals__ = {
31 "feed-discovered" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
34 def __init__(self, id, job):
35 JobHandler.__init__(self, id, job)
37 def _on_fetch_started(self, handler, task):
38 pass
40 def _on_url_fetched(self, handler, task_result):
41 url = task_result.task.user_data
42 fetch_result = task_result.result
44 if feedfinder.couldBeFeedData(fetch_result.content):
45 feed = SummaryParser.parse(fetch_result.content, location = url)
46 self._notify("feed-discovered", feed)
48 def _on_fetch_done(self, handler, data):
49 pass
51 def _prepare(self):
52 self.observers = [{ "task-done": [ self._on_url_fetched ],
53 "task-start": [ self._on_fetch_started ],
54 "job-done": [ self._on_fetch_done ]}]
56 def _run(self):
57 fetch_task = Fetcher.create_task(url = self.job.url, credentials = self.job.credentials, user_data = None)
58 fetch_result = fetch_task.fetch()
60 if fetch_result.error:
61 return
63 if feedfinder.couldBeFeedData(fetch_result.content):
64 feed = SummaryParser.parse(fetch_result.content, location = self.job.url)
66 if self.job.credentials:
67 print self.job.credentials
68 feed.pdict["username"], feed.pdict["password"], domain = self.job.credentials
70 self._notify("feed-discovered", feed)
71 return
73 urls = feedfinder.urls(self.job.url, fetch_result.content)
74 fetch_tasks = [Fetcher.create_task(url = url, user_data = url) for url in urls]
75 self.fetcher_id = Fetcher.fetch(fetch_tasks, observers = self.observers, wait = True)
77 class FeedDiscoveryJob(Job):
78 def __init__(self, url, credentials, observers):
79 Job.__init__(self, "feed-discovery")
81 self.observers = observers
82 self.url = url
83 self.credentials = credentials
85 JobManager.register_handler(FeedDiscoveryJobHandler)
87 def discover(url, credentials, observers):
88 job = FeedDiscoveryJob(url, credentials, observers)
89 JobManager.start(job)