Mercurial > pidgin
comparison finch/libgnt/pygnt/example/rss/gntrss.py @ 18731:6976a6dae441
Add support for auto-refreshing. There should be some way to change the
refresh timeout for each feed, though.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Tue, 31 Jul 2007 12:03:46 +0000 |
parents | 3db31505e42f |
children | 2e41a68009ba |
comparison
equal
deleted
inserted
replaced
18730:54a28e05e8af | 18731:6976a6dae441 |
---|---|
54 except: | 54 except: |
55 item['date'] = self.date = time.ctime() | 55 item['date'] = self.date = time.ctime() |
56 self.date_parsed = feedparser._parse_date(self.date) | 56 self.date_parsed = feedparser._parse_date(self.date) |
57 | 57 |
58 self.title = item['title'] | 58 self.title = item['title'] |
59 self.summary = item['summary'] | 59 sum = item['summary'] |
60 self.summary = item['summary'].encode('utf8') | |
60 self.link = item['link'] | 61 self.link = item['link'] |
61 self.parent = parent | 62 self.parent = parent |
62 self.unread = True | 63 self.unread = True |
63 | 64 |
64 def remove(self): | 65 def remove(self): |
109 } | 110 } |
110 __gsignals__ = { | 111 __gsignals__ = { |
111 'added' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT,)) | 112 'added' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT,)) |
112 } | 113 } |
113 | 114 |
114 def __init__(self, url): | 115 def __init__(self, feed): |
115 self.__gobject_init__() | 116 self.__gobject_init__() |
117 url = feed['link'] | |
118 name = feed['name'] | |
116 self.url = url # The url of the feed itself | 119 self.url = url # The url of the feed itself |
117 self.link = url # The web page associated with the feed | 120 self.link = url # The web page associated with the feed |
118 self.desc = url | 121 self.desc = url |
119 self.title = url | 122 self.title = (name, url)[not name] |
123 self.customtitle = name | |
120 self.unread = 0 | 124 self.unread = 0 |
121 self.items = [] | 125 self.items = [] |
122 self.hash = {} | 126 self.hash = {} |
123 self.pending = False | 127 self.pending = False |
128 self._refresh = {'time' : 30, 'id' : 0} | |
124 | 129 |
125 def do_set_property(self, property, value): | 130 def do_set_property(self, property, value): |
126 if property.name == 'link': | 131 if property.name == 'link': |
127 self.link = value | 132 self.link = value |
128 elif property.name == 'desc': | 133 elif property.name == 'desc': |
160 self.items.append(itm) | 165 self.items.append(itm) |
161 self.emit('added', itm) | 166 self.emit('added', itm) |
162 self.hash[item_hash(item)] = itm | 167 self.hash[item_hash(item)] = itm |
163 unread = unread + 1 | 168 unread = unread + 1 |
164 | 169 |
170 if unread != self.unread: | |
171 self.set_property('unread', unread) | |
172 | |
165 for hv in tmp: | 173 for hv in tmp: |
166 tmp[hv].remove() | 174 tmp[hv].remove() |
167 | 175 "Also notify the UI about the count change" |
168 if unread != self.unread: | 176 |
169 self.set_property('unread', unread) | |
170 self.pending = False | 177 self.pending = False |
171 return False | 178 return False |
172 | 179 |
173 def refresh(self): | 180 def refresh(self): |
174 if self.pending: | 181 if self.pending: |
175 return | 182 return |
176 self.pending = True | 183 self.pending = True |
177 FeedReader(self).run() | 184 FeedReader(self).run() |
185 return True | |
178 | 186 |
179 def mark_read(self): | 187 def mark_read(self): |
180 for item in self.items: | 188 for item in self.items: |
181 item.mark_unread(False) | 189 item.mark_unread(False) |
190 | |
191 def set_auto_refresh(self, auto): | |
192 if auto: | |
193 if self._refresh['id']: | |
194 return | |
195 if self._refresh['time'] < 1: | |
196 self._refresh['time'] = 1 | |
197 self.id = gobject.timeout_add(self._refresh['time'] * 1000 * 60, self.refresh) | |
198 else: | |
199 if not self._refresh['id']: | |
200 return | |
201 gobject.source_remove(self._refresh['id']) | |
202 self._refresh['id'] = 0 | |
182 | 203 |
183 gobject.type_register(Feed) | 204 gobject.type_register(Feed) |
184 | 205 |
185 """ | 206 """ |
186 The FeedReader updates a Feed. It fork()s off a child to avoid blocking. | 207 The FeedReader updates a Feed. It fork()s off a child to avoid blocking. |
206 # Do NOT close tmpfile here | 227 # Do NOT close tmpfile here |
207 os._exit(os.EX_OK) | 228 os._exit(os.EX_OK) |
208 gobject.child_watch_add(self.pid, self.reap_child) | 229 gobject.child_watch_add(self.pid, self.reap_child) |
209 | 230 |
210 feeds = [] | 231 feeds = [] |
211 urls = ("http://rss.slashdot.org/Slashdot/slashdot", | 232 urls = ( |
212 "http://kerneltrap.org/node/feed", | 233 {'name': '/.', |
213 "http://pidgin.im/rss.php", | 234 'link': "http://rss.slashdot.org/Slashdot/slashdot"}, |
214 "http://www.formula1.com/rss/news/latest.rss", | 235 {'name': 'KernelTrap', |
215 "http://www.pheedo.com/f/freshmeatnet_announcements_unix", | 236 'link': "http://kerneltrap.org/node/feed"}, |
216 "http://www.cricinfo.com/rss/livescores.xml" | 237 {'name': None, |
217 ) | 238 'link': "http://pidgin.im/rss.php"}, |
239 {'name': "F1", | |
240 'link': "http://www.formula1.com/rss/news/latest.rss"}, | |
241 {'name': "Freshmeat", | |
242 'link': "http://www.pheedo.com/f/freshmeatnet_announcements_unix"}, | |
243 {'name': "Cricinfo", | |
244 'link': "http://www.cricinfo.com/rss/livescores.xml"} | |
245 ) | |
218 | 246 |
219 for url in urls: | 247 for url in urls: |
220 feed = Feed(url) | 248 feed = Feed(url) |
221 feeds.append(feed) | 249 feeds.append(feed) |
222 | 250 |