annotate finch/libgnt/pygnt/example/rss/gntrss.py @ 18727:778f4fc8cbcc

Parse HTML and show bold, italic etc. in the textview.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 30 Jul 2007 23:57:47 +0000
parents 1aeda1e812a8
children 3db31505e42f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
18715
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
3 """
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
4 gr - An RSS-reader built using libgnt and feedparser.
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
5
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
6 Copyright (C) 2007 Sadrul Habib Chowdhury <sadrul@pidgin.im>
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
7
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
8 This application is free software; you can redistribute it and/or
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
9 modify it under the terms of the GNU Lesser General Public
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
10 License as published by the Free Software Foundation; either
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
11 version 2.1 of the License, or (at your option) any later version.
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
12
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
13 This application is distributed in the hope that it will be useful,
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
16 Lesser General Public License for more details.
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
17
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
18 You should have received a copy of the GNU Lesser General Public
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
19 License along with this application; if not, write to the Free Software
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
21 USA
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
22 """
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
23
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
24 """
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
25 This file deals with the rss parsing part (feedparser) of the application
64a7b13d3b8d Update the license info.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18714
diff changeset
26 """
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
27
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
28 import threading
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29 import feedparser
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30 import gobject
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 import sys
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 import time
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
33
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 ##
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35 # 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
36 # destroyed.
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
37 ##
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
38 class FeedItem(gobject.GObject):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
39 __gproperties__ = {
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
40 'unread' : (gobject.TYPE_BOOLEAN, 'read',
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
41 'The unread state of the item.',
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
42 False, gobject.PARAM_READWRITE)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
43 }
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
44 __gsignals__ = {
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
45 '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
46 }
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
47 def __init__(self, item, parent):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
48 self.__gobject_init__()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
49 self.date = item['date']
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
50 self.date_parsed = item['date_parsed']
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
51 self.title = item['title']
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
52 self.summary = item['summary']
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
53 self.link = item['link']
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
54 self.parent = parent
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
55 self.unread = True
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
56
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
57 def remove(self):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
58 self.emit('delete', self.parent)
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
59 if self.unread:
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
60 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
61
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
62 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
63 if property.name == 'unread':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
64 self.unread = value
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
65
18722
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
66 def mark_unread(self, unread):
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
67 if self.unread == unread:
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
68 return
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
69 self.set_property('unread', unread)
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
70
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
71 gobject.type_register(FeedItem)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
72
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
73 def item_hash(item):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
74 return str(item['date'] + item['title'])
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
75
18722
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
76 """
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
77 The Feed class. It will update the 'link', 'title', 'desc' and 'items'
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
78 attributes if/when they are updated (triggering 'notify::<attr>' signal)
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
79
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
80 TODO:
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
81 - Add a 'count' attribute
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
82 - Each feed will have a 'uidata', which will be its display window
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
83 - Look into 'category'. Is it something that feed defines, or the user?
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
84 - Have separate refresh times for each feed.
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
85 - Have 'priority' for each feed. (somewhat like category, perhaps?)
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
86 """
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
87 class Feed(gobject.GObject):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
88 __gproperties__ = {
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
89 'link' : (gobject.TYPE_STRING, 'link',
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
90 '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
91 '...', gobject.PARAM_READWRITE),
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
92 'title' : (gobject.TYPE_STRING, 'title',
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
93 'The title of the feed.',
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
94 '...', gobject.PARAM_READWRITE),
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
95 'desc' : (gobject.TYPE_STRING, 'description',
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
96 'The description for the feed.',
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
97 '...', gobject.PARAM_READWRITE),
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
98 'items' : (gobject.TYPE_POINTER, 'items',
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
99 '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
100 'unread' : (gobject.TYPE_INT, 'unread',
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
101 '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
102 }
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
103 __gsignals__ = {
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
104 '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
105 }
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
106
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
107 def __init__(self, url):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
108 self.__gobject_init__()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
109 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
110 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
111 self.desc = url
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
112 self.title = url
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
113 self.unread = 0
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
114 self.timer = 0
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
115 self.items = []
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
116 self.hash = {}
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
117
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
118 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
119 if property.name == 'link':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
120 self.link = value
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
121 elif property.name == 'desc':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
122 self.desc = value
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
123 elif property.name == 'title':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
124 self.title = value
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
125 elif property.name == 'unread':
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
126 self.unread = value
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
127 pass
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
128
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
129 def check_thread_for_death(self):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
130 #if self.thread.running:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
131 # sys.stderr.write(time.ctime() + "continue")
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
132 # return True
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
133 # The thread has ended!!
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
134 #result = self.thread.result
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
135 #self.thread = None
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
136 result = feedparser.parse(self.url)
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
137 # 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
138 # 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
139
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
140 channel = result['channel']
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
141 self.set_property('link', channel['link'])
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
142 self.set_property('desc', channel['description'])
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
143 self.set_property('title', channel['title'])
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
144 self.timer = 0
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
145 items = result['items']
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
146 tmp = {}
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
147 for item in self.items:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
148 tmp[hash(item)] = item
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
149
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
150 unread = self.unread
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
151 for item in items:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
152 try:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
153 exist = self.hash[item_hash(item)]
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
154 del tmp[hash(exist)]
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
155 except:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
156 itm = FeedItem(item, self)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
157 self.items.append(itm)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
158 self.emit('added', itm)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
159 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
160 unread = unread + 1
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
161
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
162 for hv in tmp:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
163 tmp[hv].remove()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
164
18714
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
165 if unread != self.unread:
121d1560346c A few updates to the rss reader.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18682
diff changeset
166 self.set_property('unread', unread)
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
167 return False
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 def refresh(self):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
170 #if self.thread == 0:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
171 # self.thread = FeedReader(self)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
172 # self.thread.start()
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
173 if self.timer == 0:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
174 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
175
18725
1aeda1e812a8 Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18722
diff changeset
176 def mark_read(self):
1aeda1e812a8 Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18722
diff changeset
177 for item in self.items:
1aeda1e812a8 Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18722
diff changeset
178 item.mark_unread(False)
1aeda1e812a8 Make things look nice in both 80x25 and in large screens.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18722
diff changeset
179
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
180 gobject.type_register(Feed)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
181
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
182 ##
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
183 # 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
184 # (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
185 ##
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
186 class FeedReader(threading.Thread):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
187 def __init__(self, feed):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
188 self.feed = feed
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
189 self.running = True
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
190 threading.Thread.__init__(self)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
191
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
192 def run(self):
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
193 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
194 self.running = True
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
195 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
196 self.running = False
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
197 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
198
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
199 feeds = []
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
200 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
201 "http://www.python.org/channews.rdf",
18722
8b5082d54c1d Make the rss-reader look and behave nicer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18715
diff changeset
202 "http://kerneltrap.org/node/feed"
18681
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
203 )
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
204
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
205 for url in urls:
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
206 feed = Feed(url)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
207 feeds.append(feed)
ef15236a0866 A proof-of-conecpt RSS reader using pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
208