From 433a943cb9d2946603a764f1bc949b2a4eb5992b Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Mon, 14 May 2018 09:19:12 +0800 Subject: [PATCH 1/2] new: dev: append tag when exist --- buku.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/buku.py b/buku.py index 21711f6..dd70f9f 100755 --- a/buku.py +++ b/buku.py @@ -2272,6 +2272,11 @@ class BukuDb: else: newtag = None + if not tacit: + append_tags_resp = input('Append tags when bookmark exist? (n/y): ') + else: + append_tags_resp = 'n' + if filepath.endswith('.md'): for item in import_md(filepath=filepath, newtag=newtag): self.add_rec(*item) @@ -2301,8 +2306,10 @@ class BukuDb: add_parent_folder_as_tag = (resp == 'y') for item in import_html(soup, add_parent_folder_as_tag, newtag): - self.add_rec(*item) - + add_rec_res = self.add_rec(*item) + if add_rec_res == -1 and append_tags_resp == 'y': + rec_id = self.get_rec_id(item[0]) + self.append_tag_at_index(rec_id, item[2]) self.conn.commit() infp.close() From 9209f3e7fa75680072aa0894299db43aa9a3e935 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Wed, 16 May 2018 06:56:03 +0800 Subject: [PATCH 2/2] chg: dev: merge code when adding record --- buku.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/buku.py b/buku.py index dd70f9f..dba4ac1 100755 --- a/buku.py +++ b/buku.py @@ -2277,15 +2277,11 @@ class BukuDb: else: append_tags_resp = 'n' + items = [] if filepath.endswith('.md'): - for item in import_md(filepath=filepath, newtag=newtag): - self.add_rec(*item) - - self.conn.commit() - + items = import_md(filepath=filepath, newtag=newtag) elif filepath.endswith('org'): - for item in import_org(filepath=filepath, newtag=newtag): - self.add_rec(*item) + items = import_org(filepath=filepath, newtag=newtag) else: try: @@ -2305,14 +2301,17 @@ class BukuDb: resp = 'y' add_parent_folder_as_tag = (resp == 'y') - for item in import_html(soup, add_parent_folder_as_tag, newtag): - add_rec_res = self.add_rec(*item) - if add_rec_res == -1 and append_tags_resp == 'y': - rec_id = self.get_rec_id(item[0]) - self.append_tag_at_index(rec_id, item[2]) - self.conn.commit() + items = import_html(soup, add_parent_folder_as_tag, newtag) infp.close() + for item in items: + add_rec_res = self.add_rec(*item) + if add_rec_res == -1 and append_tags_resp == 'y': + rec_id = self.get_rec_id(item[0]) + self.append_tag_at_index(rec_id, item[2]) + + self.conn.commit() + if newtag: print('\nAuto-generated tag: %s' % newtag)