2015-11-01 14:04:41 -06:00
|
|
|
#!/usr/bin/python3
|
2015-11-01 14:08:45 -06:00
|
|
|
#
|
|
|
|
# Bookmark management utility
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Arun Prakash Jana <engineerarun@gmail.com>
|
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
2015-11-01 14:04:41 -06:00
|
|
|
|
2015-11-04 08:11:16 -06:00
|
|
|
import sys
|
2015-11-06 14:26:08 -06:00
|
|
|
import os
|
2015-11-01 14:04:41 -06:00
|
|
|
import sqlite3
|
2015-11-04 08:11:16 -06:00
|
|
|
from getopt import getopt, GetoptError
|
2015-11-06 13:26:20 -06:00
|
|
|
import readline
|
2015-11-06 13:59:57 -06:00
|
|
|
import webbrowser
|
2015-11-06 16:32:08 -06:00
|
|
|
import html.parser as HTMLParser
|
2015-11-07 07:29:38 -06:00
|
|
|
from http.client import HTTPConnection
|
2015-11-06 17:07:15 -06:00
|
|
|
from http.client import HTTPSConnection
|
2015-11-07 13:19:59 -06:00
|
|
|
from urllib.parse import urljoin, unquote
|
2015-11-04 08:11:16 -06:00
|
|
|
|
2015-11-04 13:07:10 -06:00
|
|
|
# Globals
|
2015-11-05 09:18:51 -06:00
|
|
|
addurl = False
|
2015-11-07 12:10:21 -06:00
|
|
|
addindex = None
|
2015-11-07 01:19:13 -06:00
|
|
|
online = False
|
2015-11-08 12:19:12 -06:00
|
|
|
delete = False
|
|
|
|
show = False
|
2015-11-05 12:26:02 -06:00
|
|
|
search = False
|
2015-11-07 07:29:38 -06:00
|
|
|
entry = None
|
2015-11-08 12:19:12 -06:00
|
|
|
update = False
|
|
|
|
debug = False
|
2015-11-04 13:07:10 -06:00
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
# Show usage of markit and exit
|
2015-11-04 08:11:16 -06:00
|
|
|
def usage():
|
|
|
|
print("Usage: markit [OPTIONS] KEYWORDS...")
|
2015-11-07 07:29:38 -06:00
|
|
|
print("Bookmark manager. Your private Google.\n")
|
2015-11-04 08:11:16 -06:00
|
|
|
print("Options")
|
2015-11-07 12:10:21 -06:00
|
|
|
print(" -a URL tag 1, tag 2, ... add a bookmark with comma separated tags")
|
|
|
|
print(" -d N delete entry at index N")
|
|
|
|
print(" -D delete ALL bookmarks")
|
|
|
|
print(" -i N add entry at index N, works with -a, use to fill deleted index")
|
|
|
|
print(" -o fetch title info from web, works with -a or -u")
|
2015-11-08 15:48:44 -06:00
|
|
|
print(" -p show all bookmarks along with real index from database")
|
2015-11-08 11:44:35 -06:00
|
|
|
print(" -s keyword(s) search all bookmarks for a (partial) tag or keywords")
|
2015-11-07 12:10:21 -06:00
|
|
|
print(" -u N update entry at index N (from output of -p)")
|
2015-11-08 12:19:12 -06:00
|
|
|
print(" -z show debug information")
|
2015-11-07 12:10:21 -06:00
|
|
|
print(" you can either add or update or delete in one instance")
|
2015-11-08 15:16:01 -06:00
|
|
|
print(" any other option shows help and exits markit\n")
|
|
|
|
print("Keys")
|
|
|
|
print(" 1-N open Nth search result in browser. Enter exits markit.\n")
|
2015-11-04 08:11:16 -06:00
|
|
|
print("Version 0.1")
|
|
|
|
print("Copyright (C) 2015 Arun Prakash Jana <engineerarun@gmail.com>")
|
|
|
|
print("Webpage: https://github.com/jarun/markit")
|
|
|
|
sys.exit(1)
|
2015-11-01 14:04:41 -06:00
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
# Initialize the database connection
|
|
|
|
# Create bookmarks table is not existing
|
2015-11-05 09:18:51 -06:00
|
|
|
def initdb():
|
2015-11-07 13:19:59 -06:00
|
|
|
user = os.environ.get('USER')
|
2015-11-05 09:18:51 -06:00
|
|
|
# Create a connection
|
2015-11-07 13:19:59 -06:00
|
|
|
conn = sqlite3.connect('/home/' + user + '/.cache/bookmarks.db')
|
2015-11-05 09:18:51 -06:00
|
|
|
cur = conn.cursor()
|
|
|
|
|
|
|
|
# Create table if it doesn't exist
|
2015-11-07 11:47:24 -06:00
|
|
|
cur.execute('''CREATE TABLE if not exists bookmarks \
|
|
|
|
(id integer PRIMARY KEY, URL text NOT NULL UNIQUE, tags text, metadata text)''')
|
2015-11-05 09:18:51 -06:00
|
|
|
conn.commit()
|
|
|
|
return (conn, cur)
|
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
# Add a new bookmark or update an existing record
|
2015-11-07 07:29:38 -06:00
|
|
|
def AddUpdateEntry(conn, cur, keywords, entry):
|
2015-11-07 01:19:13 -06:00
|
|
|
global online
|
|
|
|
|
2015-11-05 09:18:51 -06:00
|
|
|
tags = ','
|
|
|
|
url = keywords[0]
|
|
|
|
for tag in keywords[1:]:
|
|
|
|
if tags[-1] == ",":
|
|
|
|
tags += tag
|
|
|
|
else:
|
|
|
|
tags += " " + tag
|
|
|
|
|
|
|
|
if tags[-1] != ",":
|
|
|
|
tags += ","
|
|
|
|
|
2015-11-06 16:32:08 -06:00
|
|
|
meta = ''
|
2015-11-06 17:07:15 -06:00
|
|
|
|
2015-11-07 01:19:13 -06:00
|
|
|
if online == True:
|
2015-11-07 07:29:38 -06:00
|
|
|
secure = True
|
2015-11-07 01:19:13 -06:00
|
|
|
if url.find("https://") >= 0:
|
|
|
|
server = url[8:]
|
|
|
|
elif url.find("http://") >= 0:
|
2015-11-07 07:29:38 -06:00
|
|
|
secure = False
|
2015-11-07 01:19:13 -06:00
|
|
|
server = url[7:]
|
|
|
|
else:
|
|
|
|
online = False
|
2015-11-06 17:07:15 -06:00
|
|
|
|
2015-11-07 01:19:13 -06:00
|
|
|
if online == True:
|
|
|
|
marker = server.find("/")
|
|
|
|
if marker > 0:
|
|
|
|
server = server[:marker]
|
|
|
|
|
|
|
|
try:
|
2015-11-08 12:19:12 -06:00
|
|
|
if debug:
|
|
|
|
print("server: [%s]" % server)
|
2015-11-07 07:29:38 -06:00
|
|
|
if secure == True:
|
|
|
|
urlconn = HTTPSConnection(server, timeout=30)
|
|
|
|
else:
|
|
|
|
urlconn = HTTPConnection(server, timeout=30)
|
2015-11-08 12:19:12 -06:00
|
|
|
|
|
|
|
if debug:
|
|
|
|
print("URL: [%s]" % url)
|
2015-11-07 01:19:13 -06:00
|
|
|
urlconn.request("GET", url)
|
|
|
|
resp = urlconn.getresponse()
|
|
|
|
if resp.status != 200:
|
2015-11-08 12:56:52 -06:00
|
|
|
# Handle first redirection
|
2015-11-07 13:06:46 -06:00
|
|
|
if resp.status in (301,302,):
|
|
|
|
redirurl = urljoin(url, resp.getheader('location', ''))
|
|
|
|
if redirurl.find("sorry/IndexRedirect?") >= 0:
|
|
|
|
print("ERROR: Connection blocked due to unusual activity.")
|
|
|
|
else:
|
|
|
|
urlconn.close()
|
|
|
|
|
|
|
|
secure = False
|
|
|
|
if url.find("https://") >= 0:
|
|
|
|
secure = True
|
|
|
|
|
|
|
|
if secure == True:
|
|
|
|
server = redirurl[8:]
|
|
|
|
marker = server.find("/")
|
|
|
|
if marker > 0:
|
|
|
|
server = server[:marker]
|
|
|
|
urlconn = HTTPSConnection(server, timeout=30)
|
|
|
|
else:
|
|
|
|
server = redirurl[7:]
|
|
|
|
marker = server.find("/")
|
|
|
|
if marker > 0:
|
|
|
|
server = server[:marker]
|
|
|
|
urlconn = HTTPConnection(server, timeout=30)
|
|
|
|
|
2015-11-08 12:19:12 -06:00
|
|
|
if debug:
|
|
|
|
print("Redir server: [%s]" % server)
|
|
|
|
print("Redir URL: [%s]" % redirurl)
|
2015-11-07 13:06:46 -06:00
|
|
|
|
|
|
|
urlconn.request("GET", redirurl)
|
|
|
|
resp = urlconn.getresponse()
|
|
|
|
if resp.status != 200:
|
|
|
|
print("ERROR on retry:", str(resp.status), ": ", resp.reason)
|
|
|
|
meta = ''
|
|
|
|
else:
|
|
|
|
parser = BMHTMLParser()
|
|
|
|
parser.feed(resp.read().decode('utf-8'))
|
|
|
|
if parser.data != None and parser.data.find("Error") < 0:
|
|
|
|
meta = parser.data
|
2015-11-08 12:56:52 -06:00
|
|
|
else: # if resp.status in (301,302,):
|
2015-11-07 13:06:46 -06:00
|
|
|
print("ERROR:", str(resp.status), ": ", resp.reason)
|
|
|
|
meta = ''
|
2015-11-08 12:56:52 -06:00
|
|
|
else: # if resp.status != 200:
|
2015-11-07 01:19:13 -06:00
|
|
|
parser = BMHTMLParser()
|
|
|
|
parser.feed(resp.read().decode('utf-8'))
|
|
|
|
if parser.data != None and parser.data.find("Error") < 0:
|
|
|
|
meta = parser.data
|
2015-11-07 07:29:38 -06:00
|
|
|
except Exception as e:
|
|
|
|
print("Exception: %s" % e)
|
2015-11-07 01:19:13 -06:00
|
|
|
meta = ''
|
|
|
|
finally:
|
|
|
|
urlconn.close()
|
|
|
|
|
2015-11-08 12:19:12 -06:00
|
|
|
print("Title: [%s]" % meta)
|
2015-11-06 16:32:08 -06:00
|
|
|
|
2015-11-07 07:29:38 -06:00
|
|
|
if entry == None: # Add a new entry
|
|
|
|
try:
|
2015-11-07 12:10:21 -06:00
|
|
|
if addindex == None:
|
|
|
|
cur.execute('INSERT INTO bookmarks(URL, tags, metadata) VALUES (?, ?, ?)', (url, tags, meta,))
|
|
|
|
else:
|
|
|
|
cur.execute('INSERT INTO bookmarks(id, URL, tags, metadata) VALUES (?, ?, ?, ?)', (int(addindex), url, tags, meta,))
|
2015-11-07 07:29:38 -06:00
|
|
|
conn.commit()
|
|
|
|
except sqlite3.IntegrityError:
|
2015-11-08 17:29:06 -06:00
|
|
|
for row in cur.execute("SELECT id from bookmarks where URL LIKE ?", (url,)):
|
|
|
|
print("URL already exists at index %s" % row[0])
|
|
|
|
return
|
|
|
|
|
|
|
|
print("Index %s exists" % addindex)
|
2015-11-07 07:29:38 -06:00
|
|
|
else: # Update an existing entry
|
|
|
|
try:
|
|
|
|
cur.execute("UPDATE bookmarks SET URL = ?, tags = ?, metadata = ? WHERE id = ?", (url, tags, meta, int(entry),))
|
|
|
|
conn.commit()
|
|
|
|
if cur.rowcount == 1:
|
|
|
|
print("Updated")
|
|
|
|
else:
|
|
|
|
print("No matching index")
|
|
|
|
except sqlite3.IntegrityError:
|
|
|
|
print("URL already exists")
|
2015-11-05 09:18:51 -06:00
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
# Search the database for a tag or mathcing URL or Title info
|
2015-11-05 12:26:02 -06:00
|
|
|
def searchdb(cur, keywords):
|
|
|
|
searchtag = ''
|
|
|
|
for token in keywords:
|
|
|
|
searchtag += token + " "
|
2015-11-08 11:44:35 -06:00
|
|
|
searchtag = searchtag[0:-1]
|
2015-11-05 12:26:02 -06:00
|
|
|
|
2015-11-08 11:44:35 -06:00
|
|
|
arguments = []
|
|
|
|
arguments.append(searchtag)
|
|
|
|
placeholder = "'%' || ? || '%'"
|
|
|
|
query = "SELECT url, metadata FROM bookmarks WHERE tags LIKE (%s)" % placeholder
|
|
|
|
for token in keywords:
|
|
|
|
query += " OR URL LIKE (%s) OR metadata LIKE (%s)" % (placeholder, placeholder)
|
|
|
|
arguments.append(token)
|
|
|
|
arguments.append(token)
|
2015-11-08 12:19:12 -06:00
|
|
|
if debug:
|
|
|
|
print("%s, (%s)" % (query, arguments))
|
2015-11-05 12:26:02 -06:00
|
|
|
|
2015-11-05 12:33:00 -06:00
|
|
|
count = 0
|
2015-11-06 13:59:57 -06:00
|
|
|
results = []
|
2015-11-08 11:44:35 -06:00
|
|
|
for row in cur.execute(query, arguments):
|
2015-11-07 01:29:40 -06:00
|
|
|
results.append(row[0])
|
2015-11-05 12:33:00 -06:00
|
|
|
count += 1
|
2015-11-07 01:29:40 -06:00
|
|
|
print("\x1B[1m\x1B[93m%d. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s" % (count, row[0], row[1]))
|
2015-11-05 12:26:02 -06:00
|
|
|
|
2015-11-06 13:59:57 -06:00
|
|
|
if count == 0:
|
|
|
|
return
|
|
|
|
|
2015-11-07 09:08:15 -06:00
|
|
|
print("")
|
|
|
|
|
2015-11-06 13:59:57 -06:00
|
|
|
while True:
|
2015-11-06 14:45:30 -06:00
|
|
|
nav = input("Index number to open: ")
|
2015-11-06 13:59:57 -06:00
|
|
|
if is_int(nav):
|
2015-11-06 14:26:08 -06:00
|
|
|
index = int(nav) - 1
|
|
|
|
if index < 0:
|
|
|
|
print("Index out of bound.")
|
|
|
|
continue
|
|
|
|
|
2015-11-06 13:59:57 -06:00
|
|
|
try:
|
2015-11-06 14:26:08 -06:00
|
|
|
_stderr = os.dup(2)
|
|
|
|
os.close(2)
|
|
|
|
_stdout = os.dup(1)
|
|
|
|
os.close(1)
|
|
|
|
fd = os.open(os.devnull, os.O_RDWR)
|
|
|
|
os.dup2(fd, 2)
|
|
|
|
os.dup2(fd, 1)
|
|
|
|
try:
|
2015-11-07 11:47:24 -06:00
|
|
|
openurl = unquote(results[int(nav) - 1])
|
|
|
|
openurl = openurl.replace("%22", "\"")
|
2015-11-07 11:48:53 -06:00
|
|
|
webbrowser.open(openurl)
|
2015-11-06 14:26:08 -06:00
|
|
|
finally:
|
|
|
|
os.close(fd)
|
|
|
|
os.dup2(_stderr, 2)
|
|
|
|
os.dup2(_stdout, 1)
|
2015-11-06 13:59:57 -06:00
|
|
|
except IndexError:
|
|
|
|
print("Index out of bound.")
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
# Delete a single record or remove the table
|
2015-11-07 07:29:38 -06:00
|
|
|
def cleardb(conn, cur, entry):
|
|
|
|
if entry == None: # Remove the table
|
|
|
|
cur.execute('DROP TABLE if exists bookmarks')
|
|
|
|
conn.commit()
|
|
|
|
else: # Remove a single entry
|
|
|
|
try:
|
|
|
|
cur.execute("DELETE FROM bookmarks WHERE id = ?", (int(entry),))
|
|
|
|
conn.commit()
|
|
|
|
if cur.rowcount == 1:
|
|
|
|
print("Removed")
|
|
|
|
else:
|
|
|
|
print("No matching index")
|
|
|
|
except IndexError:
|
|
|
|
print("Index out of bound.")
|
2015-11-05 09:18:51 -06:00
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
# Print all records in the table
|
2015-11-08 12:19:12 -06:00
|
|
|
def printdb(cur):
|
2015-11-05 09:18:51 -06:00
|
|
|
for row in cur.execute('SELECT * FROM bookmarks'):
|
2015-11-06 14:45:30 -06:00
|
|
|
print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t[TAGS] %s\n\t[META] %s" % (row[0], row[1], row[2][1:-1], row[3]))
|
2015-11-05 09:18:51 -06:00
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
# Check if a value is a digit
|
2015-11-06 13:59:57 -06:00
|
|
|
def is_int(string):
|
|
|
|
try:
|
|
|
|
int(string)
|
|
|
|
return True
|
|
|
|
except:
|
|
|
|
return False
|
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
# Parse HTML page for Title info
|
2015-11-06 16:32:08 -06:00
|
|
|
class BMHTMLParser(HTMLParser.HTMLParser):
|
|
|
|
def __init__(self):
|
|
|
|
HTMLParser.HTMLParser.__init__(self)
|
|
|
|
self.inTitle = False
|
|
|
|
self.data = ""
|
|
|
|
self.lasttag = None
|
|
|
|
|
|
|
|
def handle_starttag(self, tag, attrs):
|
|
|
|
self.inTitle = False
|
|
|
|
if tag == "title":
|
|
|
|
self.inTitle = True
|
|
|
|
self.lasttag = tag
|
|
|
|
|
|
|
|
def handle_endtag(self, tag):
|
|
|
|
if tag == "title":
|
|
|
|
self.inTitle = False
|
|
|
|
|
|
|
|
def handle_data(self, data):
|
|
|
|
if self.lasttag == "title" and self.inTitle == True:
|
2015-11-07 07:29:38 -06:00
|
|
|
self.data += data
|
2015-11-06 16:32:08 -06:00
|
|
|
|
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
|
2015-11-01 14:04:41 -06:00
|
|
|
# Main starts here
|
|
|
|
# ----------------
|
2015-11-04 08:11:16 -06:00
|
|
|
optlist = None
|
|
|
|
keywords = None
|
|
|
|
|
|
|
|
if len(sys.argv) < 2:
|
|
|
|
usage()
|
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
# Check cmdline options
|
2015-11-04 08:11:16 -06:00
|
|
|
try:
|
2015-11-08 12:19:12 -06:00
|
|
|
optlist, keywords = getopt(sys.argv[1:], "d:i:u:aDopsz")
|
2015-11-06 13:59:57 -06:00
|
|
|
if len(optlist) < 1:
|
|
|
|
usage()
|
|
|
|
|
2015-11-04 08:11:16 -06:00
|
|
|
for opt in optlist:
|
2015-11-05 09:18:51 -06:00
|
|
|
if opt[0] == "-a":
|
2015-11-08 12:19:12 -06:00
|
|
|
if update == True or delete == True:
|
2015-11-07 07:29:38 -06:00
|
|
|
print("You can either add or update or delete in one instance\n")
|
2015-11-05 21:40:44 -06:00
|
|
|
usage()
|
|
|
|
|
2015-11-05 09:18:51 -06:00
|
|
|
addurl = True
|
2015-11-04 08:11:16 -06:00
|
|
|
elif opt[0] == "-d":
|
2015-11-08 12:19:12 -06:00
|
|
|
if addurl == True or update == True:
|
2015-11-07 07:29:38 -06:00
|
|
|
print("You can either add or update or delete in one instance\n")
|
|
|
|
usage()
|
|
|
|
|
|
|
|
if not opt[1].isdigit():
|
|
|
|
usage()
|
|
|
|
|
|
|
|
entry = opt[1]
|
|
|
|
if int(entry) <= 0:
|
|
|
|
usage()
|
|
|
|
|
2015-11-08 12:19:12 -06:00
|
|
|
delete = True
|
2015-11-07 07:29:38 -06:00
|
|
|
elif opt[0] == "-D":
|
2015-11-08 12:19:12 -06:00
|
|
|
if addurl == True or update == True:
|
2015-11-07 07:29:38 -06:00
|
|
|
print("You can either add or update or delete in one instance\n")
|
|
|
|
usage()
|
|
|
|
|
2015-11-08 12:19:12 -06:00
|
|
|
delete = True
|
2015-11-07 12:10:21 -06:00
|
|
|
elif opt[0] == "-i":
|
|
|
|
if not opt[1].isdigit():
|
|
|
|
usage()
|
|
|
|
|
|
|
|
addindex = opt[1]
|
|
|
|
if int(addindex) <= 0:
|
|
|
|
usage()
|
2015-11-07 01:19:13 -06:00
|
|
|
elif opt[0] == "-o":
|
|
|
|
online = True
|
2015-11-05 09:18:51 -06:00
|
|
|
elif opt[0] == "-p":
|
2015-11-08 12:19:12 -06:00
|
|
|
show = True
|
2015-11-05 12:26:02 -06:00
|
|
|
elif opt[0] == "-s":
|
|
|
|
search = True
|
2015-11-05 21:40:44 -06:00
|
|
|
elif opt[0] == "-u":
|
2015-11-08 12:19:12 -06:00
|
|
|
if addurl == True or delete == True:
|
2015-11-07 07:29:38 -06:00
|
|
|
print("You can either add or update or delete in one instance\n")
|
2015-11-05 21:40:44 -06:00
|
|
|
usage()
|
2015-11-07 07:29:38 -06:00
|
|
|
|
2015-11-05 21:40:44 -06:00
|
|
|
if not opt[1].isdigit():
|
|
|
|
usage()
|
|
|
|
|
|
|
|
entry = opt[1]
|
|
|
|
if int(entry) <= 0:
|
|
|
|
usage()
|
|
|
|
|
2015-11-08 12:19:12 -06:00
|
|
|
update = True
|
|
|
|
elif opt[0] == "-z":
|
|
|
|
debug = True
|
2015-11-04 08:11:16 -06:00
|
|
|
except GetoptError as e:
|
|
|
|
print("markit:", e)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
# Initilize the database and get handles
|
2015-11-05 09:18:51 -06:00
|
|
|
conn, cur = initdb()
|
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
# To insert (-i) a new record at user-defined index, -a option is must
|
2015-11-07 12:10:21 -06:00
|
|
|
if addindex != None and addurl == False:
|
|
|
|
conn.close()
|
|
|
|
usage()
|
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
# Call add or update record
|
2015-11-08 12:19:12 -06:00
|
|
|
if addurl == True or update == True:
|
2015-11-05 09:18:51 -06:00
|
|
|
if len(keywords) < 1:
|
2015-11-07 12:10:21 -06:00
|
|
|
conn.close()
|
2015-11-05 09:18:51 -06:00
|
|
|
usage()
|
|
|
|
|
2015-11-07 07:29:38 -06:00
|
|
|
AddUpdateEntry(conn, cur, keywords, entry)
|
2015-11-05 09:18:51 -06:00
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
# Search tags, URLs, Title info
|
2015-11-05 12:26:02 -06:00
|
|
|
if search == True:
|
|
|
|
if len(keywords) < 1:
|
2015-11-07 12:10:21 -06:00
|
|
|
conn.close()
|
2015-11-05 12:26:02 -06:00
|
|
|
usage()
|
|
|
|
|
|
|
|
searchdb(cur, keywords)
|
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
# Print all records
|
2015-11-08 12:19:12 -06:00
|
|
|
if show == True:
|
|
|
|
printdb(cur)
|
2015-11-04 21:54:10 -06:00
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
# Remove a single record of all records
|
2015-11-08 12:19:12 -06:00
|
|
|
if delete == True:
|
2015-11-07 07:29:38 -06:00
|
|
|
cleardb(conn, cur, entry)
|
2015-11-05 21:40:44 -06:00
|
|
|
|
2015-11-08 12:56:52 -06:00
|
|
|
# Close the connection before exiting
|
2015-11-01 14:04:41 -06:00
|
|
|
conn.close()
|