From 7cea0059184035c6d4413062ce1317cd512e5196 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sat, 26 May 2018 09:29:34 +0530 Subject: [PATCH] Reformat API to return URL --- README.md | 2 +- buku.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 06d023c..2a7f6d8 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ `buku` is a powerful bookmark manager written in Python3 and SQLite3. When I started writing it, I couldn't find a flexible cmdline solution with a private, portable, merge-able database along with seamless GUI integration. Hence, `Buku` (after my son's nickname, meaning *close to the heart* in my language). -`buku` fetches the title of a bookmarked url and stores it along with any user-provided comments and tags. You can use your favourite editor to compose and update bookmarks. With multiple search options, including regex and a deep scan mode (particularly for URLs), it can find any bookmark instantly. Multiple search results can be opened in the browser at once. There's an Easter egg to revisit random forgotten bookmarks too! +`buku` fetches the title of a bookmarked url and stores it along with any user-provided comments and tags. You can use your favourite editor to compose and update bookmarks. With multiple search options, including regex and a deep scan mode (particularly for URLs), it can find any bookmark instantly. Multiple search results can be opened in the browser at once. `buku` can look up the latest snapshot of a broken link on the Wayback Machine. There's an Easter egg to revisit random forgotten bookmarks too! For GUI and browser integration (or to sync bookmarks with your favourite bookmark management service), refer to the wiki page on [System integration](https://github.com/jarun/Buku/wiki/System-integration). If you prefer the terminal, the [shell completion](#shell-completion) scripts can be handy. diff --git a/buku.py b/buku.py index fb3cd4d..55288b5 100755 --- a/buku.py +++ b/buku.py @@ -2433,8 +2433,8 @@ class BukuDb: Returns ------- - bool - True on success, False on failure. + str + Wayback Machine URL, None if not cached """ from urllib.parse import quote_plus @@ -2443,7 +2443,7 @@ class BukuDb: rec = self.get_rec_by_id(int(arg)) if not rec: logerr('No matching index %d', int(arg)) - return False + return None else: url = rec[1] else: @@ -2456,14 +2456,15 @@ class BukuDb: respobj = json.loads(resp.data.decode('utf-8')) try: if len(respobj['archived_snapshots']) and respobj['archived_snapshots']['closest']['available'] is True: - browse(respobj['archived_snapshots']['closest']['url']) - return True + manager.clear() + return respobj['archived_snapshots']['closest']['url'] except Exception: pass finally: manager.clear() - return False + logerr('Uncached') + return None def fixtags(self): """Undocumented API to fix tags set in earlier versions. @@ -4783,8 +4784,9 @@ POSITIONAL ARGUMENTS: # Try to fetch URL from Wayback Machine if args.cached: - if bdb.browse_cached_url(args.cached[0]) is False: - logerr('Not cached') + wbu = bdb.browse_cached_url(args.cached[0]) + if wbu is not None: + browse(wbu) # Report upstream version if args.upstream: