Mercurial > pidgin
annotate 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 |
rev | line source |
---|---|
18681
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
2 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
3 # A very simple and stupid RSS reader |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
4 # |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
5 # Uses the Universal Feed Parser |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
6 # |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
7 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
8 import threading |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
9 import feedparser |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
10 import gobject |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
11 import sys |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
12 import time |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
13 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
14 ## |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
15 # The FeedItem class. It will update emit 'delete' signal when it's |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
16 # destroyed. |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
17 ## |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
18 class FeedItem(gobject.GObject): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
19 __gproperties__ = { |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
20 'unread' : (gobject.TYPE_BOOLEAN, 'read', |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
21 'The unread state of the item.', |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
22 False, gobject.PARAM_READWRITE) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
23 } |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
24 __gsignals__ = { |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
25 'delete' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT,)) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
26 } |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
27 def __init__(self, item, parent): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
28 self.__gobject_init__() |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
29 self.date = item['date'] |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
30 self.date_parsed = item['date_parsed'] |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
31 self.title = item['title'] |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
32 self.summary = item['summary'] |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
33 self.link = item['link'] |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
34 self.parent = parent |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
35 self.unread = True |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
36 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
37 def remove(self): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
38 self.emit('delete', self.parent) |
18714
121d1560346c
A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18682
diff
changeset
|
39 if self.unread: |
121d1560346c
A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18682
diff
changeset
|
40 self.parent.set_property('unread', self.parent.unread - 1) |
18681
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
41 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
42 def do_set_property(self, property, value): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
43 if property.name == 'unread': |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
44 self.unread = value |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
45 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
46 gobject.type_register(FeedItem) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
47 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
48 def item_hash(item): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
49 return str(item['date'] + item['title']) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
50 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
51 ## |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
52 # The Feed class. It will update the 'link', 'title', 'desc' and 'items' |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
53 # attributes if/when they are updated (triggering 'notify::<attr>' signal) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
54 ## |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
55 class Feed(gobject.GObject): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
56 __gproperties__ = { |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
57 'link' : (gobject.TYPE_STRING, 'link', |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
58 'The web page this feed is associated with.', |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
59 '...', gobject.PARAM_READWRITE), |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
60 'title' : (gobject.TYPE_STRING, 'title', |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
61 'The title of the feed.', |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
62 '...', gobject.PARAM_READWRITE), |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
63 'desc' : (gobject.TYPE_STRING, 'description', |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
64 'The description for the feed.', |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
65 '...', gobject.PARAM_READWRITE), |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
66 'items' : (gobject.TYPE_POINTER, 'items', |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
67 'The items in the feed.', gobject.PARAM_READWRITE), |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
68 'unread' : (gobject.TYPE_INT, 'unread', |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
69 'Number of unread items in the feed.', 0, 10000, 0, gobject.PARAM_READWRITE) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
70 } |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
71 __gsignals__ = { |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
72 'added' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT,)) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
73 } |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
74 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
75 def __init__(self, url): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
76 self.__gobject_init__() |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
77 self.url = url # The url of the feed itself |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
78 self.link = url # The web page associated with the feed |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
79 self.desc = url |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
80 self.title = url |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
81 self.unread = 0 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
82 self.timer = 0 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
83 self.items = [] |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
84 self.hash = {} |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
85 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
86 def do_set_property(self, property, value): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
87 if property.name == 'link': |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
88 self.link = value |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
89 elif property.name == 'desc': |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
90 self.desc = value |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
91 elif property.name == 'title': |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
92 self.title = value |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
93 elif property.name == 'unread': |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
94 self.unread = value |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
95 pass |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
96 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
97 def check_thread_for_death(self): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
98 #if self.thread.running: |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
99 # sys.stderr.write(time.ctime() + "continue") |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
100 # return True |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
101 # The thread has ended!! |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
102 #result = self.thread.result |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
103 #self.thread = None |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
104 result = feedparser.parse(self.url) |
18714
121d1560346c
A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18682
diff
changeset
|
105 # XXX Look at result['bozo'] first, and emit some signal that the UI can use |
121d1560346c
A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18682
diff
changeset
|
106 # to indicate (dim the row?) that the feed has invalid XML format or something |
121d1560346c
A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18682
diff
changeset
|
107 |
18681
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
108 channel = result['channel'] |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
109 self.set_property('link', channel['link']) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
110 self.set_property('desc', channel['description']) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
111 self.set_property('title', channel['title']) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
112 self.timer = 0 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
113 items = result['items'] |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
114 tmp = {} |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
115 for item in self.items: |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
116 tmp[hash(item)] = item |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
117 |
18714
121d1560346c
A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18682
diff
changeset
|
118 unread = self.unread |
18681
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
119 for item in items: |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
120 try: |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
121 exist = self.hash[item_hash(item)] |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
122 del tmp[hash(exist)] |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
123 except: |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
124 itm = FeedItem(item, self) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
125 self.items.append(itm) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
126 self.emit('added', itm) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
127 self.hash[item_hash(item)] = itm |
18714
121d1560346c
A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18682
diff
changeset
|
128 unread = unread + 1 |
121d1560346c
A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18682
diff
changeset
|
129 |
18681
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
130 for hv in tmp: |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
131 tmp[hv].remove() |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
132 |
18714
121d1560346c
A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18682
diff
changeset
|
133 if unread != self.unread: |
121d1560346c
A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18682
diff
changeset
|
134 self.set_property('unread', unread) |
18681
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
135 return False |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
136 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
137 def refresh(self): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
138 #if self.thread == 0: |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
139 # self.thread = FeedReader(self) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
140 # self.thread.start() |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
141 if self.timer == 0: |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
142 self.timer = gobject.timeout_add(1000, self.check_thread_for_death) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
143 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
144 gobject.type_register(Feed) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
145 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
146 ## |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
147 # A FeedReader class, which is threaded to make sure it doesn't freeze the ui |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
148 # (this thing doesn't quite work ... yet) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
149 ## |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
150 class FeedReader(threading.Thread): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
151 def __init__(self, feed): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
152 self.feed = feed |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
153 self.running = True |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
154 threading.Thread.__init__(self) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
155 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
156 def run(self): |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
157 sys.stderr.write(str(time.ctime()) + " STARTED!!!\n\n\n") |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
158 self.running = True |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
159 self.result = feedparser.parse(self.feed.url) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
160 self.running = False |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
161 sys.stderr.write(str(time.ctime()) + " DONE!!!\n\n\n") |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
162 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
163 feeds = [] |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
164 urls = ("http://rss.slashdot.org/Slashdot/slashdot", |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
165 "http://www.python.org/channews.rdf", |
18682
254823d66aa5
The promised cleanups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18681
diff
changeset
|
166 "http://pidgin.im/rss.php" |
18681
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
167 ) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
168 |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
169 for url in urls: |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
170 feed = Feed(url) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
171 feeds.append(feed) |
ef15236a0866
A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
172 |