Print data as json if option is set in printdb
This commit is contained in:
parent
c1ae9254c1
commit
d7bbab6d5d
31
buku
31
buku
@ -366,21 +366,32 @@ def printdb(cur, index):
|
|||||||
global jsonOutput
|
global jsonOutput
|
||||||
|
|
||||||
if index == None: # Show all entries
|
if index == None: # Show all entries
|
||||||
for row in cur.execute('SELECT * FROM bookmarks'):
|
resultset = cur.execute('SELECT * FROM bookmarks')
|
||||||
if showOpt == 1:
|
if jsonOutput == False:
|
||||||
print("%s %s" % (row[0], row[1]))
|
for row in resultset:
|
||||||
elif showOpt == 2:
|
if showOpt == 1:
|
||||||
print("%s %s %s" % (row[0], row[1], row[3][1:-1]))
|
print("%s %s" % (row[0], row[1]))
|
||||||
else:
|
elif showOpt == 2:
|
||||||
print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t\x1B[91m[TAGS]\x1B[0m %s" % (row[0], row[1], row[2], row[3][1:-1]))
|
print("%s %s %s" % (row[0], row[1], row[3][1:-1]))
|
||||||
|
else:
|
||||||
|
print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t\x1B[91m[TAGS]\x1B[0m %s" % (row[0], row[1], row[2], row[3][1:-1]))
|
||||||
|
else:
|
||||||
|
print(formatJson(resultset))
|
||||||
|
|
||||||
else: # Show record at index
|
else: # Show record at index
|
||||||
try:
|
try:
|
||||||
for row in cur.execute("SELECT * FROM bookmarks WHERE id = ?", (int(index),)):
|
resultset = cur.execute("SELECT * FROM bookmarks WHERE id = ?", (int(index),))
|
||||||
|
except IndexError:
|
||||||
|
print("Index out of bound")
|
||||||
|
|
||||||
|
if jsonOutput == False:
|
||||||
|
for row in resultset:
|
||||||
print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t\x1B[91m[TAGS]\x1B[0m %s" % (row[0], row[1], row[2], row[3][1:-1]))
|
print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t\x1B[91m[TAGS]\x1B[0m %s" % (row[0], row[1], row[2], row[3][1:-1]))
|
||||||
return
|
return
|
||||||
print("No matching index")
|
print("No matching index")
|
||||||
except IndexError:
|
else:
|
||||||
print("Index out of bound")
|
print(formatJson(resultset, True))
|
||||||
|
|
||||||
def formatJson(resultset, single=False):
|
def formatJson(resultset, single=False):
|
||||||
global showOpt
|
global showOpt
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user