deskbar-applet r2282 - in branches/gnome-2-22: . deskbar/handlers
- From: sebp svn gnome org
- To: svn-commits-list gnome org
- Subject: deskbar-applet r2282 - in branches/gnome-2-22: . deskbar/handlers
- Date: Sun, 3 Aug 2008 13:30:11 +0000 (UTC)
Author: sebp
Date: Sun Aug 3 13:30:11 2008
New Revision: 2282
URL: http://svn.gnome.org/viewvc/deskbar-applet?rev=2282&view=rev
Log:
Adjusted url to RSS feeds. Check if content is formatted properly before parsing it. Fixes bug #544645
Modified:
branches/gnome-2-22/ChangeLog
branches/gnome-2-22/deskbar/handlers/desklicious.py
Modified: branches/gnome-2-22/deskbar/handlers/desklicious.py
==============================================================================
--- branches/gnome-2-22/deskbar/handlers/desklicious.py (original)
+++ branches/gnome-2-22/deskbar/handlers/desklicious.py Sun Aug 3 13:30:11 2008
@@ -19,8 +19,8 @@
GCONF_DELICIOUS_USER = GconfStore.GCONF_DIR+"/desklicious/user"
-DEFAULT_QUERY_TAG = 'http://del.icio.us/rss/%s/%s'
-QUERY_DELAY = 1
+DEFAULT_QUERY_TAG = 'http://feeds.delicious.com/rss/%s/%s'
+
HANDLERS = ["DeliciousHandler"]
class DeliciousAction(ShowUrlAction):
@@ -69,8 +69,6 @@
LOGGER.info( "Asking del.icio.us tags for %s" % tag )
posts = self._delicious.get_posts_by_tag(tag)
- # TODO: Missing
- #self.check_query_changed (timeout=QUERY_DELAY)
LOGGER.info('Returning del.icio.us result')
self.set_priority_for_matches( posts )
self._emit_query_ready(tag, posts )
@@ -135,45 +133,63 @@
if self._user == None:
return []
- posts=[]
+ posts = []
#Get the info from del.icio.us and parse
url = DEFAULT_QUERY_TAG % (urllib.quote_plus(self._user), urllib.quote_plus(tag))
LOGGER.debug("Opening URL %s", url)
stream = None
try:
- try:
- stream = urllib.urlopen(url, proxies=deskbar.core.Utils.get_proxy())
- dom = xml.dom.minidom.parse(stream)
- except IOError, msg:
- LOGGER.error("Could not open URL %s: %s, %s", url, msg[0], msg[1])
- except ExpatError, e:
- LOGGER.exception(e)
- finally:
- if stream != None:
- stream.close()
+ stream = urllib.urlopen(url, proxies=deskbar.core.Utils.get_proxy())
+ except IOError, msg:
+ LOGGER.error("Could not open URL %s: %s, %s", url, msg[0], msg[1])
+ return []
+
+ try:
+ dom = xml.dom.minidom.parse(stream)
+ except ExpatError, e:
+ LOGGER.exception(e)
+ return []
+
+ if stream != None:
+ stream.close()
#And return the results
try:
try:
for item in dom.getElementsByTagName("item"):
- title_node = item.getElementsByTagName("title")[0]
- url_node = item.getElementsByTagName("link")[0]
- subject_node = item.getElementsByTagName("dc:subject")[0]
- creator_node = item.getElementsByTagName("dc:creator")[0]
+ title_nodes = item.getElementsByTagName("title")
+ url_nodes = item.getElementsByTagName("link")
+
+ # Check if we have expected content at all
+ if len(title_nodes) == 0 or len(url_nodes) == 0:
+ return []
+
+ item_title = title_nodes[0].firstChild.nodeValue
+ item_url = url_nodes[0].firstChild.nodeValue
+
+ # by default we have no tags
+ tags = []
+ subject_nodes = item.getElementsByTagName("dc:subject")
+ if len(subject_nodes) > 0:
+ subject_node = subject_nodes[0]
+ # There might be no tags
+ if (subject_node.hasChildNodes()):
+ tags = subject_node.firstChild.nodeValue.split(" ")
- # There might be no tags
- if (subject_node.hasChildNodes()):
- tags = subject_node.firstChild.nodeValue.split(" ")
+ creator_nodes = item.getElementsByTagName("dc:creator")
+ if len(creator_nodes) > 0:
+ creator_node = creator_nodes[0]
+ creator = creator_node.firstChild.nodeValue
else:
- tags = []
+ creator = self._user
posts.append(
DeliciousMatch(
- name=title_node.firstChild.nodeValue,
- url=url_node.firstChild.nodeValue,
+ name=item_title,
+ url=item_url,
tags=tags,
- author=creator_node.firstChild.nodeValue,
+ author=creator,
category="web"))
except DOMException, e:
LOGGER.exception(e)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]