insert functional but deprecated by auto-compact.
This commit is contained in:
parent
ef1ccfd59e
commit
fb2c886ec5
55
buku
55
buku
@ -50,7 +50,6 @@ except ImportError:
|
||||
|
||||
|
||||
# Globals
|
||||
addindex = None # DB index to insert URL into
|
||||
showOpt = 0 # Modify show. 1: show only URL, 2: show URL and tag
|
||||
entry = None # DB index to update or delete
|
||||
update = False # Update a bookmark in DB
|
||||
@ -347,11 +346,11 @@ def isBookmarkAdded(cur, url):
|
||||
|
||||
|
||||
|
||||
def AddUpdateEntry(conn, cur, keywords, index):
|
||||
"""Add a new bookmark or update an existing record at index
|
||||
or insert a new record at addindex (if empty)
|
||||
def AddUpdateEntry(conn, cur, keywords, updateindex, insertindex=0):
|
||||
"""Add a new bookmark or update an existing record at
|
||||
updateindex or insert a new record at insertindex (if empty)
|
||||
|
||||
Params: connection, cursor, index to update
|
||||
Params: connection, cursor, keywords, index to update, index to insert at
|
||||
"""
|
||||
|
||||
global titleManual
|
||||
@ -362,7 +361,7 @@ def AddUpdateEntry(conn, cur, keywords, index):
|
||||
"""In case of an add or insert operation ensure
|
||||
that the URL does not exist in DB already
|
||||
"""
|
||||
if index is None:
|
||||
if updateindex is None:
|
||||
id = isBookmarkAdded(cur, url)
|
||||
if id != -1:
|
||||
print("URL already exists at index %d" % id)
|
||||
@ -387,7 +386,7 @@ def AddUpdateEntry(conn, cur, keywords, index):
|
||||
if tags[-1] != ',':
|
||||
tags += ','
|
||||
|
||||
if titleManual != None:
|
||||
if titleManual is not None:
|
||||
if titleManual == "none":
|
||||
meta = ''
|
||||
else:
|
||||
@ -399,12 +398,12 @@ def AddUpdateEntry(conn, cur, keywords, index):
|
||||
else:
|
||||
print("Title: [%s]" % meta)
|
||||
|
||||
if index == None: # Insert a new entry
|
||||
if updateindex is None: # Add or insert a new entry
|
||||
try:
|
||||
if addindex == None: # addindex is index number to insert record at
|
||||
if insertindex == 0: # insertindex is index number to insert record at
|
||||
cur.execute('INSERT INTO bookmarks(URL, metadata, tags) VALUES (?, ?, ?)', (url, meta, tags,))
|
||||
else:
|
||||
cur.execute('INSERT INTO bookmarks(id, URL, metadata, tags) VALUES (?, ?, ?, ?)', (int(addindex), url, meta, tags,))
|
||||
cur.execute('INSERT INTO bookmarks(id, URL, metadata, tags) VALUES (?, ?, ?, ?)', (insertindex, url, meta, tags,))
|
||||
conn.commit()
|
||||
print("Added at index %d\n" % cur.lastrowid)
|
||||
printdb(cur, cur.lastrowid)
|
||||
@ -413,14 +412,14 @@ def AddUpdateEntry(conn, cur, keywords, index):
|
||||
print("URL already exists at index %s" % row[0])
|
||||
return
|
||||
|
||||
print("Index %s exists" % addindex)
|
||||
print("Index %d exists" % insertindex)
|
||||
else: # Update an existing entry
|
||||
try:
|
||||
cur.execute("UPDATE bookmarks SET URL = ?, metadata = ?, tags = ? WHERE id = ?", (url, meta, tags, int(index),))
|
||||
cur.execute("UPDATE bookmarks SET URL = ?, metadata = ?, tags = ? WHERE id = ?", (url, meta, tags, int(updateindex),))
|
||||
conn.commit()
|
||||
if cur.rowcount == 1:
|
||||
print("Updated index %d\n" % int(index))
|
||||
printdb(cur, int(index))
|
||||
print("Updated index %d\n" % int(updateindex))
|
||||
printdb(cur, int(updateindex))
|
||||
else:
|
||||
print("No matching index")
|
||||
except sqlite3.IntegrityError:
|
||||
@ -475,7 +474,7 @@ def searchdb(cur, keywords, all_keywords=False):
|
||||
"""Search the database for an entries with tags or URL
|
||||
or title info matching keywords and list those.
|
||||
|
||||
Params: cursor, keywords to search
|
||||
Params: cursor, keywords to search, search any or all keywords
|
||||
"""
|
||||
|
||||
global jsonOutput
|
||||
@ -1041,8 +1040,8 @@ addarg('-u', '--update', nargs='+', dest='update', metavar=('N', 'URL tags'),
|
||||
help='update fields of the entry at DB index N. The first keyword, if available, is treated as the URL. If URL is omitted (and -m is not used) the title of entry at index N is refreshed from the web, N=0 refreshes all titles.')
|
||||
addarg('-e', '--empty', dest='empty', action='store_true', # DONE
|
||||
help='show bookmarks with empty titles or no tags')
|
||||
addarg('-i', '--insert', dest='insert', nargs='+', metavar=('N', 'URL tags'),
|
||||
help='insert new bookmark with URL and tags at free DB index N')
|
||||
#addarg('-i', '--insert', nargs='+', dest='insert', metavar=('N', 'URL tags'),
|
||||
# help='insert new bookmark with URL and tags at free DB index N; frees index if URL and tags are omitted')
|
||||
addarg('-j', '--json', dest='jsonOutput', action='store_true', # DONE
|
||||
help='show results in Json format')
|
||||
addarg('-k', '--decrypt', dest='decrypt', action='store_true', # DONE
|
||||
@ -1109,8 +1108,8 @@ try:
|
||||
if not opt[1].isdigit():
|
||||
usage()
|
||||
|
||||
addindex = opt[1]
|
||||
if int(addindex) <= 0:
|
||||
insertindex = opt[1]
|
||||
if int(insertindex) <= 0:
|
||||
usage()
|
||||
|
||||
addurl = True
|
||||
@ -1274,6 +1273,24 @@ if args.replace is not None:
|
||||
if args.empty == True:
|
||||
printdb(cur, 0, True)
|
||||
|
||||
'''
|
||||
# Insert a record at an index
|
||||
if args.insert is not None:
|
||||
if not args.insert[0].isdigit():
|
||||
printmsg("Index must be a number >= 1", "ERROR")
|
||||
conn.close()
|
||||
sys.exit(1)
|
||||
insertindex = int(args.insert[0])
|
||||
if insertindex < 1:
|
||||
printmsg("Index must be a number >= 1", "ERROR")
|
||||
conn.close()
|
||||
sys.exit(1)
|
||||
if len(args.insert) == 1:
|
||||
pass # We need to add logic here to empty
|
||||
else:
|
||||
AddUpdateEntry(conn, cur, args.insert[1:], None, insertindex)
|
||||
'''
|
||||
|
||||
# Open URL in browser
|
||||
if args.openurl is not None:
|
||||
if args.openurl < 1:
|
||||
|
Loading…
x
Reference in New Issue
Block a user