Implement comma (,) sseparated tags.

Signed-off-by: Arun Prakash Jana <engineerarun@gmail.com>
This commit is contained in:
Arun Prakash Jana 2015-11-05 09:24:10 +05:30
parent a3cf3da6fa
commit 1f12afc85e

24
markit
View File

@ -23,7 +23,7 @@ from getopt import getopt, GetoptError
# Globals # Globals
url = '' url = ''
tags = '' tags = ','
def usage(): def usage():
print("Usage: markit [OPTIONS] KEYWORDS...") print("Usage: markit [OPTIONS] KEYWORDS...")
@ -96,9 +96,16 @@ print("key: [%s]" % keywords[0])
url = keywords[0] url = keywords[0]
for tag in keywords[1:]: for tag in keywords[1:]:
print("tag: [%s]" % tag) print("tag: [%s]" % tag)
tags += tag + " " if tags[-1] == ",":
tags += tag
else:
tags += " " + tag
tags = tags[0:-1] #tags += tag + " "
#tags = tags[0:-1]
if tags[-1] != ",":
tags += ","
print("tags: [%s]" % tags) print("tags: [%s]" % tags)
# Create a connection # Create a connection
@ -106,7 +113,7 @@ conn = sqlite3.connect('bookmarks.db')
c = conn.cursor() c = conn.cursor()
# Create table if it doesn't exist # Create table if it doesn't exist
c.execute('''DROP TABLE if exists bookmarks''') #c.execute('''DROP TABLE if exists bookmarks''')
c.execute('''CREATE TABLE if not exists bookmarks c.execute('''CREATE TABLE if not exists bookmarks
(id integer PRIMARY KEY AUTOINCREMENT, URL text NOT NULL UNIQUE, tags text, metadata text)''') (id integer PRIMARY KEY AUTOINCREMENT, URL text NOT NULL UNIQUE, tags text, metadata text)''')
@ -115,9 +122,12 @@ c.execute('INSERT INTO bookmarks(URL, tags, metadata) VALUES (?, ?, ?)', (url, t
#c.execute("INSERT INTO bookmarks(URL, tags, metadata) VALUES ('www.google.com','search engine','')") #c.execute("INSERT INTO bookmarks(URL, tags, metadata) VALUES ('www.google.com','search engine','')")
conn.commit() conn.commit()
# Search the table for row in c.execute('SELECT * FROM bookmarks'):
t = ('hello',)
for row in c.execute("SELECT * FROM bookmarks WHERE tags LIKE ('%' || ? || '%')", t):
print(row) print(row)
# Search the table
#t = ('hello',)
#for row in c.execute("SELECT * FROM bookmarks WHERE tags LIKE ('%' || ? || '%')", t):
# print(row)
conn.close() conn.close()