Mercurial > pidgin.yaz
comparison finch/libgnt/pygnt/example/rss/gntrss.py @ 18714:121d1560346c
A few updates to the rss reader.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 29 Jul 2007 10:37:10 +0000 |
parents | 254823d66aa5 |
children | 64a7b13d3b8d |
comparison
equal
deleted
inserted
replaced
18713:8000beb73585 | 18714:121d1560346c |
---|---|
34 self.parent = parent | 34 self.parent = parent |
35 self.unread = True | 35 self.unread = True |
36 | 36 |
37 def remove(self): | 37 def remove(self): |
38 self.emit('delete', self.parent) | 38 self.emit('delete', self.parent) |
39 if self.unread: | |
40 self.parent.set_property('unread', self.parent.unread - 1) | |
39 | 41 |
40 def do_set_property(self, property, value): | 42 def do_set_property(self, property, value): |
41 if property.name == 'unread': | 43 if property.name == 'unread': |
42 self.unread = value | 44 self.unread = value |
43 | 45 |
98 # return True | 100 # return True |
99 # The thread has ended!! | 101 # The thread has ended!! |
100 #result = self.thread.result | 102 #result = self.thread.result |
101 #self.thread = None | 103 #self.thread = None |
102 result = feedparser.parse(self.url) | 104 result = feedparser.parse(self.url) |
105 # XXX Look at result['bozo'] first, and emit some signal that the UI can use | |
106 # to indicate (dim the row?) that the feed has invalid XML format or something | |
107 | |
103 channel = result['channel'] | 108 channel = result['channel'] |
104 self.set_property('link', channel['link']) | 109 self.set_property('link', channel['link']) |
105 self.set_property('desc', channel['description']) | 110 self.set_property('desc', channel['description']) |
106 self.set_property('title', channel['title']) | 111 self.set_property('title', channel['title']) |
107 self.set_property('unread', len(result['items'])) | |
108 self.timer = 0 | 112 self.timer = 0 |
109 items = result['items'] | 113 items = result['items'] |
110 tmp = {} | 114 tmp = {} |
111 for item in self.items: | 115 for item in self.items: |
112 tmp[hash(item)] = item | 116 tmp[hash(item)] = item |
113 | 117 |
118 unread = self.unread | |
114 for item in items: | 119 for item in items: |
115 try: | 120 try: |
116 exist = self.hash[item_hash(item)] | 121 exist = self.hash[item_hash(item)] |
117 del tmp[hash(exist)] | 122 del tmp[hash(exist)] |
118 except: | 123 except: |
119 itm = FeedItem(item, self) | 124 itm = FeedItem(item, self) |
120 self.items.append(itm) | 125 self.items.append(itm) |
121 self.emit('added', itm) | 126 self.emit('added', itm) |
122 self.hash[item_hash(item)] = itm | 127 self.hash[item_hash(item)] = itm |
128 unread = unread + 1 | |
129 | |
123 for hv in tmp: | 130 for hv in tmp: |
124 tmp[hv].remove() | 131 tmp[hv].remove() |
125 | 132 |
133 if unread != self.unread: | |
134 self.set_property('unread', unread) | |
126 return False | 135 return False |
127 | 136 |
128 def refresh(self): | 137 def refresh(self): |
129 #if self.thread == 0: | 138 #if self.thread == 0: |
130 # self.thread = FeedReader(self) | 139 # self.thread = FeedReader(self) |