Add append tag support.
This commit is contained in:
parent
07ed8da4c3
commit
87397e3788
65
buku
65
buku
@ -436,12 +436,37 @@ class BukuDb:
|
||||
except Exception as e:
|
||||
print('\x1b[1mEXCEPTION\x1b[21m [add_bookmark]: (%s) %s' % (type(e).__name__, e))
|
||||
|
||||
def update_bookmark(self, index, url='', title_manual=None, tag_manual=None, desc=None):
|
||||
def append_tag_at_index(self, index, tag_manual):
|
||||
""" Append tags for bookmark at index
|
||||
|
||||
:param index: int position of record, 0 for all
|
||||
:tag_manual: string of comma-separated tags to add manually
|
||||
"""
|
||||
|
||||
if index == 0:
|
||||
resp = input('Tags will be appended for ALL bookmarks. Enter \x1b[1my\x1b[21m to confirm: ')
|
||||
if resp != 'y':
|
||||
return
|
||||
|
||||
self.cur.execute('SELECT id, tags FROM bookmarks ORDER BY id ASC')
|
||||
else:
|
||||
self.cur.execute('SELECT id, tags FROM bookmarks WHERE id = ?', (index,))
|
||||
|
||||
resultset = self.cur.fetchall()
|
||||
for row in resultset:
|
||||
tags = '%s%s' % (row[1], tag_manual[1:])
|
||||
tags = parse_tags([tags])
|
||||
self.cur.execute('UPDATE bookmarks SET tags = ? WHERE id = ?', (tags, row[0],))
|
||||
|
||||
self.conn.commit()
|
||||
|
||||
def update_bookmark(self, index, url='', title_manual=None,
|
||||
tag_manual=None, desc=None, append_tag=False):
|
||||
""" Update an existing record at index
|
||||
Update all records if index is 0 and url is not specified.
|
||||
URL is an exception because URLs are unique in DB.
|
||||
|
||||
:param index: int position to update
|
||||
:param index: int position to update, 0 for all
|
||||
:param url: address
|
||||
:param tag_manual: string of comma-separated tags to add manually
|
||||
:param title_manual: string title to add manually
|
||||
@ -461,9 +486,12 @@ class BukuDb:
|
||||
|
||||
# Update tags if passed as argument
|
||||
if tag_manual is not None:
|
||||
query = '%s tags = ?,' % query
|
||||
arguments += (tag_manual,)
|
||||
to_update = True
|
||||
if append_tag:
|
||||
self.append_tag_at_index(index, tag_manual)
|
||||
else:
|
||||
query = '%s tags = ?,' % query
|
||||
arguments += (tag_manual,)
|
||||
to_update = True
|
||||
|
||||
# Update description if passed as an argument
|
||||
if desc is not None:
|
||||
@ -487,7 +515,7 @@ class BukuDb:
|
||||
print('\x1B[91mTitle: []\x1B[0m')
|
||||
elif debug:
|
||||
print('Title: [%s]' % meta)
|
||||
elif not to_update:
|
||||
elif not to_update and not append_tag:
|
||||
self.refreshdb(index)
|
||||
if index > 0:
|
||||
self.print_bookmark(index)
|
||||
@ -668,7 +696,8 @@ class BukuDb:
|
||||
Print only bookmarks with blank title or tag if empty is True
|
||||
Note: URL is printed on top because title may be blank
|
||||
|
||||
Params: index to print, flag to show only bookmarks with no title or tags
|
||||
Params: index to print (0 for all)
|
||||
empty flag to show only bookmarks with no title or tags
|
||||
"""
|
||||
|
||||
if index == 0: # Show all entries
|
||||
@ -982,6 +1011,7 @@ def connect_server(url, fullurl=False, forced=False):
|
||||
|
||||
urlconn.request('GET', url, None, {
|
||||
'Accept-encoding': 'gzip',
|
||||
'DNT': '1',
|
||||
})
|
||||
return (urlconn, urlconn.getresponse())
|
||||
|
||||
@ -1558,8 +1588,15 @@ if __name__ == '__main__':
|
||||
tags = DELIMITER
|
||||
keywords = args.addurl
|
||||
if tagManual is not None:
|
||||
# Add DELIMITER as url+tags may not end with comma
|
||||
keywords = args.addurl + [DELIMITER] + tagManual
|
||||
if tagManual[0] == '+' and len(tagManual) == 1:
|
||||
pass
|
||||
elif tagManual[0] == '+':
|
||||
tagManual = tagManual[1:]
|
||||
# In case of add, args.addurl may have URL followed by tags
|
||||
# Add DELIMITER as url+tags may not end with comma
|
||||
keywords = args.addurl + [DELIMITER] + tagManual
|
||||
else:
|
||||
keywords = args.addurl + [DELIMITER] + tagManual
|
||||
|
||||
if len(keywords) > 1:
|
||||
tags = parse_tags(keywords[1:])
|
||||
@ -1581,10 +1618,18 @@ if __name__ == '__main__':
|
||||
else:
|
||||
new_url = ''
|
||||
|
||||
append = False
|
||||
if tagManual is not None:
|
||||
if tagManual[0] == '+' and len(tagManual) == 1:
|
||||
tagManual = None
|
||||
elif tagManual[0] == '+':
|
||||
tagManual = tagManual[1:]
|
||||
append = True
|
||||
|
||||
# Parse tags into a comma-separated string
|
||||
tags = parse_tags(tagManual)
|
||||
|
||||
bdb.update_bookmark(update_index, new_url, titleManual, tags, description)
|
||||
bdb.update_bookmark(update_index, new_url, titleManual, tags, description, append)
|
||||
|
||||
# Delete record(s)
|
||||
if args.delete is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user