API to fix tags from earlier versions. Update image.
This commit is contained in:
parent
ff8bc645a6
commit
1609b5a135
@ -9,7 +9,7 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://asciinema.org/a/93515"><img src="https://asciinema.org/a/93515.png" alt="Asciicast" width="734"/></a>
|
||||
<a href="https://asciinema.org/a/9l6s2ppivpo661nu5slwk2t6y"><img src="https://asciinema.org/a/9l6s2ppivpo661nu5slwk2t6y.png" alt="Asciicast" width="734"/></a>
|
||||
</p>
|
||||
|
||||
`buku` is a powerful bookmark management utility written in Python3 and SQLite3. When I started writing it, I couldn't find a flexible cmdline solution with a private, portable, merge-able database along with browser integration. Hence, `buku` (after my son's nickname).
|
||||
|
36
buku.py
36
buku.py
@ -1417,6 +1417,34 @@ Buku bookmarks</H3>
|
||||
|
||||
return r.text
|
||||
|
||||
def fixtags(self):
|
||||
'''Undocumented API to fix tags set
|
||||
in earlier versions. Functionalities:
|
||||
|
||||
1. Remove duplicate tags
|
||||
2. Sort tags
|
||||
3. Use lower case to store tags
|
||||
'''
|
||||
|
||||
to_commit = False
|
||||
self.cur.execute('SELECT id, tags FROM bookmarks ORDER BY id ASC')
|
||||
resultset = self.cur.fetchall()
|
||||
query = 'UPDATE bookmarks SET tags = ? WHERE id = ?'
|
||||
for row in resultset:
|
||||
oldtags = row[1]
|
||||
if oldtags == ',':
|
||||
continue
|
||||
|
||||
tags = parse_tags([oldtags])
|
||||
if tags == oldtags:
|
||||
continue
|
||||
|
||||
self.cur.execute(query, (tags, row[0],))
|
||||
to_commit = True
|
||||
|
||||
if to_commit:
|
||||
self.conn.commit()
|
||||
|
||||
def close_quit(self, exitval=0):
|
||||
'''Close a DB connection and exit
|
||||
|
||||
@ -1634,7 +1662,7 @@ def parse_tags(keywords=None):
|
||||
orig_tags += tags.strip(DELIM).split(DELIM)
|
||||
for tag in orig_tags:
|
||||
if tag.lower() not in unique_tags:
|
||||
# Add unique tags in lowercase
|
||||
# Add unique tags in lower case
|
||||
unique_tags += (tag.lower(), )
|
||||
|
||||
# Sort the tags
|
||||
@ -2269,6 +2297,8 @@ def main():
|
||||
addarg('--tacit', action='store_true', help=HIDE)
|
||||
addarg('--upstream', action='store_true', help=HIDE)
|
||||
addarg('-z', '--debug', action='store_true', help=HIDE)
|
||||
# Undocumented API
|
||||
addarg('--fixtags', action='store_true', help=HIDE)
|
||||
|
||||
# Show help and exit if no arguments
|
||||
if len(sys.argv) < 2:
|
||||
@ -2530,6 +2560,10 @@ def main():
|
||||
if args.upstream:
|
||||
check_upstream_release()
|
||||
|
||||
# Fix tags
|
||||
if args.fixtags:
|
||||
bdb.fixtags()
|
||||
|
||||
# Close DB connection and quit
|
||||
bdb.close_quit(0)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user