Implement full DB refresh.

Signed-off-by: Arun Prakash Jana <engineerarun@gmail.com>
This commit is contained in:
Arun Prakash Jana 2015-11-13 16:42:12 +05:30
parent 4bb704f3bf
commit bd71bf3b97
3 changed files with 29 additions and 3 deletions

View File

@ -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

28
markit
View File

@ -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:

View File

@ -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