Add parent folder as tag in same loop
This commit is contained in:
parent
c81cb03f55
commit
55e0eb5767
52
buku.py
52
buku.py
@ -1600,7 +1600,7 @@ class BukuDb:
|
|||||||
print('%s exported' % count)
|
print('%s exported' % count)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def importdb(self, filepath):
|
def importdb(self, filepath, tacit=False):
|
||||||
'''Import bookmarks from a html or a markdown
|
'''Import bookmarks from a html or a markdown
|
||||||
file (with extension '.md'). Supports Firefox,
|
file (with extension '.md'). Supports Firefox,
|
||||||
Google Chrome and IE exported html
|
Google Chrome and IE exported html
|
||||||
@ -1609,6 +1609,11 @@ class BukuDb:
|
|||||||
:return: True on success, False on failure
|
:return: True on success, False on failure
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
if not tacit:
|
||||||
|
newtag = input('Specify unique tag for imports (Enter to skip): ')
|
||||||
|
else:
|
||||||
|
newtag = None
|
||||||
|
|
||||||
if filepath.endswith('.md'):
|
if filepath.endswith('.md'):
|
||||||
with open(filepath, mode='r', encoding='utf-8') as infp:
|
with open(filepath, mode='r', encoding='utf-8') as infp:
|
||||||
for line in infp:
|
for line in infp:
|
||||||
@ -1629,7 +1634,8 @@ class BukuDb:
|
|||||||
if (is_nongeneric_url(url)):
|
if (is_nongeneric_url(url)):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.add_rec(url, title, None, None, 0, True)
|
self.add_rec(url, title, delim_wrap(newtag)
|
||||||
|
if newtag else None, None, 0, True)
|
||||||
|
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
infp.close()
|
infp.close()
|
||||||
@ -1645,11 +1651,24 @@ class BukuDb:
|
|||||||
logerr(e)
|
logerr(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
html_tags = soup.findAll('a')
|
|
||||||
|
|
||||||
resp = input('Add imported folders names as tags? (y/n): ')
|
resp = input('Add imported folders names as tags? (y/n): ')
|
||||||
if resp == 'y':
|
|
||||||
for tag in html_tags:
|
for tag in soup.findAll('a'):
|
||||||
|
# Extract comment from <dd> tag
|
||||||
|
try:
|
||||||
|
if (is_nongeneric_url(tag['href'])):
|
||||||
|
continue
|
||||||
|
except KeyError as e:
|
||||||
|
continue
|
||||||
|
|
||||||
|
desc = None
|
||||||
|
comment_tag = tag.findNextSibling('dd')
|
||||||
|
|
||||||
|
if comment_tag:
|
||||||
|
desc = comment_tag.find(text=True, recursive=False)
|
||||||
|
|
||||||
|
# add parent folder as tag
|
||||||
|
if resp == 'y':
|
||||||
# could be its folder or not
|
# could be its folder or not
|
||||||
possible_folder = tag.find_previous('h3')
|
possible_folder = tag.find_previous('h3')
|
||||||
# get list of tags within that folder
|
# get list of tags within that folder
|
||||||
@ -1663,19 +1682,12 @@ class BukuDb:
|
|||||||
else:
|
else:
|
||||||
tag['tags'] = possible_folder.text
|
tag['tags'] = possible_folder.text
|
||||||
|
|
||||||
for tag in html_tags:
|
# add unique tag if opted
|
||||||
# Extract comment from <dd> tag
|
if newtag:
|
||||||
try:
|
if tag.has_attr('tags'):
|
||||||
if (is_nongeneric_url(tag['href'])):
|
tag['tags'] += (DELIM + newtag)
|
||||||
continue
|
else:
|
||||||
except KeyError as e:
|
tag['tags'] = newtag
|
||||||
continue
|
|
||||||
|
|
||||||
desc = None
|
|
||||||
comment_tag = tag.findNextSibling('dd')
|
|
||||||
|
|
||||||
if comment_tag:
|
|
||||||
desc = comment_tag.find(text=True, recursive=False)
|
|
||||||
|
|
||||||
self.add_rec(tag['href'], tag.string, parse_tags([tag['tags']])
|
self.add_rec(tag['href'], tag.string, parse_tags([tag['tags']])
|
||||||
if tag.has_attr('tags') else None, desc, 0, True)
|
if tag.has_attr('tags') else None, desc, 0, True)
|
||||||
@ -3286,7 +3298,7 @@ POSITIONAL ARGUMENTS:
|
|||||||
|
|
||||||
# Import bookmarks
|
# Import bookmarks
|
||||||
if args.importfile is not None:
|
if args.importfile is not None:
|
||||||
bdb.importdb(args.importfile[0])
|
bdb.importdb(args.importfile[0], args.tacit)
|
||||||
|
|
||||||
# Merge a database file and exit
|
# Merge a database file and exit
|
||||||
if args.merge is not None:
|
if args.merge is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user