X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fbkmk_rsimple.py;h=69636d9ef09044905962a3930fc8789e32b45ebc;hb=7fd1132c4ab530b7b34e846ca45f99b8737dd127;hp=67d1fbe66239c8cc9fcf312d1fec3eda1f187b84;hpb=a38eb2c9d04e866177c80cb961712ed3d4574f5e;p=bookmarks_db.git diff --git a/Robots/bkmk_rsimple.py b/Robots/bkmk_rsimple.py index 67d1fbe..69636d9 100644 --- a/Robots/bkmk_rsimple.py +++ b/Robots/bkmk_rsimple.py @@ -105,9 +105,6 @@ icons = {} # Icon cache; maps URL to a tuple (content type, data) class robot_simple(Robot): def check_url(self, bookmark): - if not self.tempfname: - self.tempfname = bookmark.tempfname - try: self.start = int(time.time()) bookmark.icon = None @@ -120,7 +117,7 @@ class robot_simple(Robot): urllib._urlopener.addheaders[2] = ('Referer', "%s://%s%s" % (url_type, url_host, url_path)) if bookmark.charset: urllib._urlopener.addheader('Accept-Charset', bookmark.charset) - fname, headers = urllib.urlretrieve("%s://%s%s" % (url_type, url_host, url_path), self.tempfname) + fname, headers = urllib.urlretrieve("%s://%s%s" % (url_type, url_host, url_path)) if bookmark.charset: del urllib._urlopener.addheaders[-1] size = 0 @@ -152,7 +149,7 @@ class robot_simple(Robot): if urllib._urlopener.type == "ftp": # Pass welcome message through MD5 md5.update(get_welcome()) - md5.md5file(self.tempfname) + md5.md5file(fname) bookmark.md5 = str(md5) if headers: @@ -215,7 +212,7 @@ class robot_simple(Robot): _icon = icon for i in range(8): try: - fname, headers = urllib.urlretrieve(_icon) + icon_fname, headers = urllib.urlretrieve(_icon) except RedirectException, e: _icon = e.url self.log(" redirect to : %s" % _icon) @@ -233,7 +230,7 @@ class robot_simple(Robot): else: content_type = headers["Content-Type"] if content_type.startswith("image/"): - icon_file = open(fname, "rb") + icon_file = open(icon_fname, "rb") icon_data = icon_file.read() icon_file.close() bookmark.icon_href = icon @@ -243,7 +240,7 @@ class robot_simple(Robot): else: self.log(" no icon : bad content type '%s'" % content_type) icons[icon] = None - os.remove(fname) + os.remove(icon_fname) except KeyError, key: self.log(" no header: %s" % key) @@ -251,18 +248,18 @@ class robot_simple(Robot): except IOError, msg: if (msg[0] == "http error") and (msg[1] == -1): bookmark.no_error = "The server did not return any header - it is not an error, actually" - self.log(bookmark.no_error) + self.log(' no headers: %s' % bookmark.no_error) else: bookmark.error = get_error(msg) - self.log(bookmark.error) + self.log(' Error: %s' % bookmark.error) except EOFError: bookmark.error = "Unexpected EOF (FTP server closed connection)" - self.log(bookmark.error) + self.log(' EOF: %s' % bookmark.error) except RedirectException, msg: bookmark.moved = str(msg) - self.log(bookmark.moved) + self.log(' Moved: %s' % bookmark.moved) except KeyboardInterrupt: self.log("Keyboard interrupt (^C)") @@ -272,19 +269,19 @@ class robot_simple(Robot): import traceback traceback.print_exc() bookmark.error = "Exception!" - self.log(bookmark.error) + self.log(' Exception: %s' % bookmark.error) finally: - self.finish_check_url(bookmark) + self.finish_check_url(bookmark, fname) # Tested return 1 - def finish_check_url(self, bookmark): + def finish_check_url(self, bookmark, fname=None): # Calculate these attributes even in case of an error - if os.path.exists(self.tempfname): - size = str(os.path.getsize(self.tempfname)) + if fname and os.path.exists(fname): + size = str(os.path.getsize(fname)) if size[-1] == 'L': size = size[:-1] bookmark.size = size