Initial search by tag implementation.
This commit is contained in:
parent
1b6c46fd1c
commit
62dad74af0
81
buku
81
buku
@ -509,36 +509,28 @@ def searchdb(cur, keywords, all_keywords=False):
|
||||
return
|
||||
|
||||
if jsonOutput == False:
|
||||
count = 0
|
||||
for row in results:
|
||||
count += 1
|
||||
printRecord(row, count)
|
||||
|
||||
if count == 0:
|
||||
return
|
||||
|
||||
while True:
|
||||
try:
|
||||
nav = input("Result number to open: ")
|
||||
except EOFError:
|
||||
return
|
||||
|
||||
if is_int(nav):
|
||||
index = int(nav) - 1
|
||||
if index < 0 or index >= count:
|
||||
print("Index out of bound")
|
||||
continue
|
||||
|
||||
try:
|
||||
browser_open(unquote(results[index][1]))
|
||||
except Exception as e:
|
||||
print("\x1b[1mEXCEPTION\x1b[21m [searchdb]: (%s) %s" % (type(e).__name__, e))
|
||||
else:
|
||||
break
|
||||
showPrompt(results)
|
||||
else:
|
||||
print(formatJson(results))
|
||||
|
||||
|
||||
def searchTag(cur, tag):
|
||||
"""Search and list bookmarks with a tag
|
||||
|
||||
Params: cursor, tag to search
|
||||
"""
|
||||
|
||||
global jsonOutput
|
||||
cur.execute("SELECT id, url, metadata, tags, desc FROM bookmarks WHERE tags LIKE '%' || ? || '%'", (tag,))
|
||||
results = cur.fetchall()
|
||||
if len(results) == 0:
|
||||
return
|
||||
|
||||
if jsonOutput == False:
|
||||
showPrompt(results)
|
||||
else:
|
||||
print(formatJson(results))
|
||||
|
||||
def compactDB(conn, cur, index):
|
||||
"""When an entry at index is deleted, move the last
|
||||
entry in DB to index, if index is lesser.
|
||||
@ -591,6 +583,34 @@ def cleardb(conn, cur, index):
|
||||
print("Index out of bound")
|
||||
|
||||
|
||||
def showPrompt(results):
|
||||
"""Show each matching result from a search"""
|
||||
|
||||
count = 0
|
||||
for row in results:
|
||||
count += 1
|
||||
printRecord(row, count)
|
||||
|
||||
while True:
|
||||
try:
|
||||
nav = input("Result number to open: ")
|
||||
except EOFError:
|
||||
return
|
||||
|
||||
if is_int(nav):
|
||||
index = int(nav) - 1
|
||||
if index < 0 or index >= count:
|
||||
print("Index out of bound")
|
||||
continue
|
||||
|
||||
try:
|
||||
browser_open(unquote(results[index][1]))
|
||||
except Exception as e:
|
||||
print("\x1b[1mEXCEPTION\x1b[21m [searchdb]: (%s) %s" % (type(e).__name__, e))
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
def printRecord(row, count=0):
|
||||
"""Print a single DB record
|
||||
Handles differently for search and print (count = 0)
|
||||
@ -1122,9 +1142,11 @@ search_group=argparser.add_argument_group(title="search options",
|
||||
search bookmarks with ALL keywords
|
||||
special keywords -
|
||||
"tags" : list all tags alphabetically
|
||||
"blank": list entries with empty title/tag''')
|
||||
"blank": list entries with empty title/tag
|
||||
--st --stag tag search bookmarks by tag''')
|
||||
search_group.add_argument('-s', '--sany', nargs='+', metavar='keyword', help=argparse.SUPPRESS)
|
||||
search_group.add_argument('-S', '--sall', nargs='+', metavar='keyword', help=argparse.SUPPRESS)
|
||||
search_group.add_argument('--st', '--stag', nargs='+', dest='stag', metavar='keyword', help=argparse.SUPPRESS)
|
||||
|
||||
# Encryption options
|
||||
crypto_group=argparser.add_argument_group(title="encryption options",
|
||||
@ -1239,6 +1261,11 @@ if args.sall is not None:
|
||||
else:
|
||||
searchdb(cur, args.sall, True)
|
||||
|
||||
# Search bookmarks by tag
|
||||
if args.stag is not None:
|
||||
tag = ',' + " ".join(args.stag) + ','
|
||||
searchTag(cur, tag)
|
||||
|
||||
# Update record
|
||||
if update == True:
|
||||
if len(args.update) == 0:
|
||||
|
Loading…
Reference in New Issue
Block a user