Print bookmark record of a single index.

Signed-off-by: Arun Prakash Jana <engineerarun@gmail.com>
This commit is contained in:
Arun Prakash Jana 2015-11-10 00:02:10 +05:30
parent 7c1195fd43
commit 9b467bc576
3 changed files with 37 additions and 11 deletions

View File

@ -65,7 +65,8 @@ Options
-D delete ALL bookmarks -D delete ALL bookmarks
-i N add entry at index N, works with -a, use to fill deleted index -i N add entry at index N, works with -a, use to fill deleted index
-o fetch title info from web, works with -a or -u -o fetch title info from web, works with -a or -u
-p show all bookmarks along with real index from database -p N show details of bookmark record at index N"
-P show all bookmarks along with real index from database
-s keyword(s) search all bookmarks for a (partial) tag or keywords -s keyword(s) search all bookmarks for a (partial) tag or keywords
-u N update entry at index N (from output of -p) -u N update entry at index N (from output of -p)
-z show debug information -z show debug information

38
markit
View File

@ -34,6 +34,7 @@ addindex = None
online = False online = False
delete = False delete = False
show = False show = False
showindex = None
search = False search = False
entry = None entry = None
update = False update = False
@ -51,7 +52,8 @@ def usage():
print(" -D delete ALL bookmarks") print(" -D delete ALL bookmarks")
print(" -i N add entry at index N, works with -a, use to fill deleted index") print(" -i N add entry at index N, works with -a, use to fill deleted index")
print(" -o fetch title info from web, works with -a or -u") print(" -o fetch title info from web, works with -a or -u")
print(" -p show all bookmarks along with real index from database") print(" -p N show details of bookmark record at index N")
print(" -P show all bookmarks along with real index from database")
print(" -s keyword(s) search all bookmarks for a (partial) tag or each keyword") print(" -s keyword(s) search all bookmarks for a (partial) tag or each keyword")
print(" -u N update entry at index N (from output of -p)") print(" -u N update entry at index N (from output of -p)")
print(" -z show debug information") print(" -z show debug information")
@ -264,7 +266,7 @@ def searchdb(cur, keywords):
if is_int(nav): if is_int(nav):
index = int(nav) - 1 index = int(nav) - 1
if index < 0: if index < 0:
print("Index out of bound.") print("Index out of bound")
continue continue
try: try:
@ -284,7 +286,7 @@ def searchdb(cur, keywords):
os.dup2(_stderr, 2) os.dup2(_stderr, 2)
os.dup2(_stdout, 1) os.dup2(_stdout, 1)
except IndexError: except IndexError:
print("Index out of bound.") print("Index out of bound")
else: else:
break break
@ -304,14 +306,23 @@ def cleardb(conn, cur, entry):
else: else:
print("No matching index") print("No matching index")
except IndexError: except IndexError:
print("Index out of bound.") print("Index out of bound")
# Print all records in the table # Print all records in the table
def printdb(cur): def printdb(cur, showindex):
for row in cur.execute('SELECT * FROM bookmarks'): if showindex == None: # Show all entries
print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t[TAGS] %s" % (row[0], row[1], row[2], row[3][1:-1])) for row in cur.execute('SELECT * FROM bookmarks'):
print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t[TAGS] %s" % (row[0], row[1], row[2], row[3][1:-1]))
else: # Show record at index showindex
try:
for row in cur.execute("SELECT * FROM bookmarks WHERE id = ?", (int(showindex),)):
print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t[TAGS] %s" % (row[0], row[1], row[2], row[3][1:-1]))
return
print("No matching index")
except IndexError:
print("Index out of bound")
@ -359,7 +370,7 @@ if len(sys.argv) < 2:
# Check cmdline options # Check cmdline options
try: try:
optlist, keywords = getopt(sys.argv[1:], "d:i:u:aDopsz") optlist, keywords = getopt(sys.argv[1:], "d:i:p:u:aDoPsz")
if len(optlist) < 1: if len(optlist) < 1:
usage() usage()
@ -399,6 +410,15 @@ try:
elif opt[0] == "-o": elif opt[0] == "-o":
online = True online = True
elif opt[0] == "-p": elif opt[0] == "-p":
if not opt[1].isdigit():
usage()
showindex = opt[1]
if int(showindex) <= 0:
usage()
show = True
elif opt[0] == "-P":
show = True show = True
elif opt[0] == "-s": elif opt[0] == "-s":
search = True search = True
@ -447,7 +467,7 @@ if search == True:
# Print all records # Print all records
if show == True: if show == True:
printdb(cur) printdb(cur, showindex)
# Remove a single record of all records # Remove a single record of all records
if delete == True: if delete == True:

View File

@ -39,7 +39,12 @@ of the database. Works only if `-a` option is used. Use this option to fill blan
.BI \-o .BI \-o
Fetch title data from the web. Works only with `-a` or `-u` options. Fetch title data from the web. Works only with `-a` or `-u` options.
.TP .TP
.B \-p .BI \-p " N"
Show details of bookmark record stored at
.I Nth
index in database.
.TP
.B \-P
Show all bookmark records from the database along with actual index. Shows URL, title data and tags. Show all bookmark records from the database along with actual index. Shows URL, title data and tags.
.TP .TP
.BI \-s " keywords" .BI \-s " keywords"