~ssh-rdp/deskbar-applet/history-count

« back to all changes in this revision

Viewing changes to deskbar/handlers/desklicious.py

  • Committer: Sebastian Pölsterl
  • Date: 2008-08-06 20:44:17 UTC
  • mfrom: (1799.1.79)
  • Revision ID: marduk@k-d-w.org-20080806204417-pggs8ixku7roce1z
Merged latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
GCONF_DELICIOUS_USER  = GconfStore.GCONF_DIR+"/desklicious/user"
21
21
 
22
 
DEFAULT_QUERY_TAG = 'http://del.icio.us/rss/%s/%s'
23
 
QUERY_DELAY = 1
 
22
DEFAULT_QUERY_TAG = 'http://feeds.delicious.com/rss/%s/%s'
 
23
 
24
24
HANDLERS = ["DeliciousHandler"]
25
25
 
26
26
class DeliciousAction(ShowUrlAction):
67
67
        LOGGER.info( "Asking del.icio.us tags for %s", tag )
68
68
        posts = self._delicious.get_posts_by_tag(tag)
69
69
 
70
 
        # TODO: Missing
71
 
        #self.check_query_changed (timeout=QUERY_DELAY)
72
70
        LOGGER.info('Returning del.icio.us result')
73
71
        self.set_priority_for_matches( posts )
74
72
        self._emit_query_ready(tag, posts )
133
131
        if self._user == None:
134
132
            return []
135
133
        
136
 
        posts=[]
 
134
        posts = []
137
135
        #Get the info from del.icio.us and parse
138
136
        url = DEFAULT_QUERY_TAG % (urllib.quote_plus(self._user), urllib.quote_plus(tag))
139
137
        
140
138
        LOGGER.debug("Opening URL %s", url)
141
139
        stream = None
142
140
        try:
143
 
            try:
144
 
                stream = urllib.urlopen(url, proxies=deskbar.core.Utils.get_proxy())
145
 
                dom = xml.dom.minidom.parse(stream)
146
 
            except IOError, msg:
147
 
                LOGGER.error("Could not open URL %s: %s, %s", url, msg[0], msg[1])
148
 
                return []
149
 
            except ExpatError, e:
150
 
                LOGGER.exception(e)
151
 
                return []
152
 
        finally:
153
 
            if stream != None:
154
 
                stream.close()
 
141
            stream = urllib.urlopen(url, proxies=deskbar.core.Utils.get_proxy())
 
142
        except IOError, msg:
 
143
            LOGGER.error("Could not open URL %s: %s, %s", url, msg[0], msg[1])
 
144
            return []
 
145
                
 
146
        try:
 
147
            dom = xml.dom.minidom.parse(stream)
 
148
        except ExpatError, e:
 
149
            LOGGER.exception(e)
 
150
            return []
 
151
        
 
152
        if stream != None:
 
153
            stream.close()
155
154
        
156
155
        #And return the results
157
156
        try:
158
157
            try:
159
158
                for item in dom.getElementsByTagName("item"):
160
 
                    title_node = item.getElementsByTagName("title")[0]
161
 
                    url_node = item.getElementsByTagName("link")[0]
162
 
                    subject_node = item.getElementsByTagName("dc:subject")[0]
163
 
                    creator_node = item.getElementsByTagName("dc:creator")[0]
164
 
                    
165
 
                    # There might be no tags
166
 
                    if (subject_node.hasChildNodes()):
167
 
                        tags = subject_node.firstChild.nodeValue.split(" ")
 
159
                    title_nodes = item.getElementsByTagName("title")
 
160
                    url_nodes = item.getElementsByTagName("link")
 
161
                    
 
162
                    # Check if we have expected content at all
 
163
                    if len(title_nodes) == 0 or len(url_nodes) == 0:
 
164
                        return []
 
165
                    
 
166
                    item_title = title_nodes[0].firstChild.nodeValue
 
167
                    item_url = url_nodes[0].firstChild.nodeValue
 
168
                    
 
169
                    # by default we have no tags
 
170
                    tags = []
 
171
                    subject_nodes = item.getElementsByTagName("dc:subject")
 
172
                    if len(subject_nodes) > 0:
 
173
                        subject_node = subject_nodes[0]
 
174
                        # There might be no tags
 
175
                        if (subject_node.hasChildNodes()):
 
176
                            tags = subject_node.firstChild.nodeValue.split(" ")
 
177
                    
 
178
                    creator_nodes = item.getElementsByTagName("dc:creator")
 
179
                    if len(creator_nodes) > 0: 
 
180
                        creator_node = creator_nodes[0]
 
181
                        creator = creator_node.firstChild.nodeValue
168
182
                    else:
169
 
                        tags = []
 
183
                        creator = self._user
170
184
                    
171
185
                    posts.append(
172
186
                        DeliciousMatch(
173
 
                            name=title_node.firstChild.nodeValue,
174
 
                            url=url_node.firstChild.nodeValue,
 
187
                            name=item_title,
 
188
                            url=item_url,
175
189
                            tags=tags,
176
 
                            author=creator_node.firstChild.nodeValue,
 
190
                            author=creator,
177
191
                            category="web"))
178
192
            except DOMException, e:
179
193
                LOGGER.exception(e)