From bd71bf3b97e89c02994ad02beba4cfcd2bee5017 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Fri, 13 Nov 2015 16:42:12 +0530 Subject: [PATCH] Implement full DB refresh. Signed-off-by: Arun Prakash Jana --- README.md | 1 + markit | 28 +++++++++++++++++++++++++--- markit.1 | 3 +++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 57bf965..e5902f4 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Options -o N open URL at DB index N in browser -p N show details of bookmark record at DB index N -P show all bookmarks along with index from DB + -R refresh all bookmarks, tags retained -s keyword(s) search all bookmarks for a (partial) tag or any keyword -S keyword(s) search all bookmarks for a (partial) tag or all keywords -u N update entry at DB index N diff --git a/markit b/markit index 122f99a..33563cc 100755 --- a/markit +++ b/markit @@ -43,6 +43,7 @@ entry = None update = False debug = False titleData = None +refresh = False @@ -58,6 +59,7 @@ def usage(): print(" -o N open URL at DB index N in browser") print(" -p N show details of bookmark record at DB index N") print(" -P show all bookmarks along with index from DB") + print(" -R refresh all bookmarks, tags retained") print(" -s keyword(s) search all bookmarks for a (partial) tag or any keyword") print(" -S keyword(s) search all bookmarks for a (partial) tag or all keywords") print(" -u N update entry at DB index N") @@ -443,7 +445,7 @@ if len(sys.argv) < 2: # Check cmdline options try: - optlist, keywords = getopt(sys.argv[1:], "d:i:o:p:u:x:aDPsSwz") + optlist, keywords = getopt(sys.argv[1:], "d:i:o:p:u:x:aDPRsSwz") if len(optlist) < 1: usage() @@ -504,6 +506,13 @@ try: show = True elif opt[0] == "-P": show = True + elif opt[0] == "-R": + if addurl == True or delete == True: + print("You can either add or update or delete in one instance\n") + usage() + + online = True + refresh = True elif opt[0] == "-s": search = True elif opt[0] == "-S": @@ -540,8 +549,8 @@ except GetoptError as e: # Initilize the database and get handles conn, cur = initdb() -# To insert (-i) a new record at user-defined index, -a option is must -if addindex != None and addurl == False: +if update == True and refresh == True: + print("You can either update a single index or refresh full DB at once.") conn.close() usage() @@ -553,6 +562,19 @@ if addurl == True or update == True: AddUpdateEntry(conn, cur, keywords, entry) +# Refresh full DB +if refresh == True: + cur.execute("SELECT id, url, tags FROM bookmarks") + for row in cur.fetchall(): + olddata = [] + olddata.append(row[1]) + if row[2] != '': + olddata.append(row[2][1:]) # Omit the initial ',' already in DB + else: + olddata.append(row[2]) + AddUpdateEntry(conn, cur, olddata, row[0]) + print("") + # Search tags, URLs, Title info if search == True: if len(keywords) < 1: diff --git a/markit.1 b/markit.1 index 76ca9dc..79b0b44 100644 --- a/markit.1 +++ b/markit.1 @@ -58,6 +58,9 @@ in DB. .B \-P Show all bookmark records from the DB along with actual index. Shows URL, title and tags. .TP +.B \-R +Refresh all bookmarks. Titles are fetched from the web. Tags are retained. +.TP .BI \-s " keywords" Search bookmarks for a (partial) tag or any keyword and show the results. Prompts to enter result number to open in browser. Note that the sequential index number may not match the real index in database. DB index is shown in the end within '()'. .TP