Create a function to output json

This commit is contained in:
lmessier 2016-03-23 00:29:45 +01:00
parent ee16a4cbc3
commit f26745714b

27
buku
View File

@ -380,8 +380,35 @@ def printdb(cur, index):
print("No matching index")
except IndexError:
print("Index out of bound")
def formatJson(resultset, single=False):
global showOpt
if single == False:
marks = []
for row in resultset:
if showOpt == 1:
record = { 'url': row[1] }
elif showOpt == 2:
record = { 'url': row[1], 'tags': row[3][1:-1] }
else:
record = { 'url': row[1], 'title': row[2], 'tags': row[3][1:-1]}
marks.append(record)
else:
marks = {}
for row in resultset:
if showOpt == 1:
marks['url'] = row[1]
elif showOpt == 2:
marks['title'] = row[2]
marks['tags'] = row[3][1:-1]
else:
marks['url'] = row[1]
marks['title'] = row[2]
marks['tags'] = row[3][1:-1]
return json.dumps(marks, sort_keys=True, indent=4)
# Show all unique tags
def showUniqueTags(cur):