Generalize bookmarks import

This change adds `firefox` and `ie` as possible arguments to the importer
script.
This commit is contained in:
Philipp Hansch 2016-03-20 10:49:33 +01:00
parent 93e0f29254
commit 8000af1664

View File

@ -21,7 +21,7 @@
"""Tool to import data from other browsers.
Currently only importing bookmarks from Chromium is supported.
Currently only importing bookmarks from Netscape Bookmark files is supported.
"""
@ -30,24 +30,27 @@ import argparse
def main():
args = get_args()
if args.browser == 'chromium':
import_chromium(args.bookmarks)
if args.browser in ['chromium', 'firefox', 'ie']:
import_netscape_bookmarks(args.bookmarks)
def get_args():
"""Get the argparse parser."""
parser = argparse.ArgumentParser(
epilog="To import bookmarks from Chromium, export them to HTML in "
"Chromium's bookmark manager.")
parser.add_argument('browser', help="Which browser?", choices=['chromium'],
epilog="To import bookmarks from Chromium, Firefox or IE, "
"export them to HTML in your browsers bookmark manager.")
parser.add_argument('browser', help="Which browser?",
choices=['chromium', 'firefox', 'ie'],
metavar='browser')
parser.add_argument('bookmarks', help="Bookmarks file")
args = parser.parse_args()
return args
def import_netscape_bookmarks(bookmarks_file):
"""Import bookmarks from a NETSCAPE-Bookmark-file v1
def import_chromium(bookmarks_file):
"""Import bookmarks from a HTML file generated by Chromium."""
Generated by Chromium, Firefox, Internet Explorer and possibly more browsers
"""
import bs4
with open(bookmarks_file, encoding='utf-8') as f:
soup = bs4.BeautifulSoup(f, 'html.parser')