From: Ed Bartosh Date: Sat, 17 Jan 2009 11:13:36 +0000 (+0000) Subject: check if connection is alive X-Git-Url: http://git.maemo.org/git/?p=xkcdha;a=commitdiff_plain;h=c6524f6a264b9d17fdce9a1ea67817ec20e22622 check if connection is alive --- diff --git a/debian/changelog b/debian/changelog index 2d5cba3..34e04d3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +xkcdha (0.0.3) unstable; urgency=low + + * check if connection is alive + + -- Ed Bartosh Sat, 17 Jan 2009 11:12:26 +0000 + xkcdha (0.0.2) unstable; urgency=low * aligned controls properly diff --git a/img/connection_required.png b/img/connection_required.png new file mode 100644 index 0000000..de56cb1 Binary files /dev/null and b/img/connection_required.png differ diff --git a/xkcdha.py b/xkcdha.py index a6891f3..4999dda 100755 --- a/xkcdha.py +++ b/xkcdha.py @@ -15,6 +15,7 @@ class XKCDha(hildondesktop.HomeItem): image_dir = "/home/user/MyDocs/.images/xkcdha/" icons_dir = "/usr/share/xkcdha/icons/" + connection_required_img = "/usr/share/xkcdha/img/connection_required.png" def __init__(self, max_height, max_width): def controls(): @@ -74,8 +75,16 @@ class XKCDha(hildondesktop.HomeItem): url = "http://xkcd.com/%s/" % number print 'url:', url + + try: + content = urllib.urlopen(url).read() + except IOError: + filename = os.path.join(self.image_dir, self.number + '.png') + if os.path.exists(filename): + return filename + else: + return self.connection_required_img - content = urllib.urlopen(url).read() img_url = re.search('(http://imgs.xkcd.com/comics/[^"]+)" title="[^"]+"', content).group(1) next = re.search('Next', content).group(1)