#!/usr/bin/python3 # # Bookmark management utility # # Copyright (C) 2015 Arun Prakash Jana # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with markit. If not, see . import sys import sqlite3 from getopt import getopt, GetoptError # Globals url = '' tags = '' def usage(): print("Usage: markit [OPTIONS] KEYWORDS...") print("Bookmark manager.\n") print("Options") print(" -p print all bookmarks") print(" -u N update index number") print(" any other input exits markit\n") print("Version 0.1") print("Copyright (C) 2015 Arun Prakash Jana ") print("Webpage: https://github.com/jarun/markit") sys.exit(1) # Main starts here # ---------------- optlist = None keywords = None if len(sys.argv) < 2: usage() try: optlist, keywords = getopt(sys.argv[1:], "s:n:c:l:t:NCjd") for opt in optlist: if opt[0] == "-s": # Option -s N if not opt[1].isdigit(): print("markit: option -s needs an integer") sys.exit(1) start = opt[1] elif opt[0] == "-n": # Option -n N if not opt[1].isdigit(): print("markit: option -n needs an integer") sys.exit(1) num = opt[1] elif opt[0] == "-N": news = True elif opt[0] == "-c": server = serverURL(opt[1]) elif opt[0] == "-l": # Option -l LANG lang = opt[1] elif opt[0] == "-C": # Option -C colorize = False elif opt[0] == "-j": # Option -j openUrl = True if num is None: num = "1" elif opt[0] == "-t": # Option -t dN duration = opt[1] if not opt[1][0] in ("h", "d","w","m","y",): usage() sys.exit(1) if not opt[1][1].isdigit(): usage() sys.exit(1) elif opt[0] == "-d": debug = True if len(keywords) < 1: usage() except GetoptError as e: print("markit:", e) sys.exit(1) print("key: [%s]" % keywords[0]) url = keywords[0] for tag in keywords[1:]: print("tag: [%s]" % tag) tags += tag + " " tags = tags[0:-1] print("tags: [%s]" % tags) # Create a connection conn = sqlite3.connect('bookmarks.db') c = conn.cursor() # Create table if it doesn't exist c.execute('''DROP TABLE if exists bookmarks''') c.execute('''CREATE TABLE if not exists bookmarks (id integer PRIMARY KEY AUTOINCREMENT, URL text NOT NULL UNIQUE, tags text, metadata text)''') # Insert values c.execute('INSERT INTO bookmarks(URL, tags, metadata) VALUES (?, ?, ?)', (url, tags, '')) #c.execute("INSERT INTO bookmarks(URL, tags, metadata) VALUES ('www.google.com','search engine','')") conn.commit() # Search the table t = ('hello',) for row in c.execute("SELECT * FROM bookmarks WHERE tags LIKE ('%' || ? || '%')", t): print(row) conn.close()