Create a function to output json
This commit is contained in:
parent
ee16a4cbc3
commit
f26745714b
27
buku
27
buku
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user