Generalize bookmarks import
This change adds `firefox` and `ie` as possible arguments to the importer script.
This commit is contained in:
parent
93e0f29254
commit
8000af1664
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
"""Tool to import data from other browsers.
|
"""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():
|
def main():
|
||||||
args = get_args()
|
args = get_args()
|
||||||
if args.browser == 'chromium':
|
if args.browser in ['chromium', 'firefox', 'ie']:
|
||||||
import_chromium(args.bookmarks)
|
import_netscape_bookmarks(args.bookmarks)
|
||||||
|
|
||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
"""Get the argparse parser."""
|
"""Get the argparse parser."""
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
epilog="To import bookmarks from Chromium, export them to HTML in "
|
epilog="To import bookmarks from Chromium, Firefox or IE, "
|
||||||
"Chromium's bookmark manager.")
|
"export them to HTML in your browsers bookmark manager.")
|
||||||
parser.add_argument('browser', help="Which browser?", choices=['chromium'],
|
parser.add_argument('browser', help="Which browser?",
|
||||||
|
choices=['chromium', 'firefox', 'ie'],
|
||||||
metavar='browser')
|
metavar='browser')
|
||||||
parser.add_argument('bookmarks', help="Bookmarks file")
|
parser.add_argument('bookmarks', help="Bookmarks file")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
def import_netscape_bookmarks(bookmarks_file):
|
||||||
|
"""Import bookmarks from a NETSCAPE-Bookmark-file v1
|
||||||
|
|
||||||
def import_chromium(bookmarks_file):
|
Generated by Chromium, Firefox, Internet Explorer and possibly more browsers
|
||||||
"""Import bookmarks from a HTML file generated by Chromium."""
|
"""
|
||||||
import bs4
|
import bs4
|
||||||
with open(bookmarks_file, encoding='utf-8') as f:
|
with open(bookmarks_file, encoding='utf-8') as f:
|
||||||
soup = bs4.BeautifulSoup(f, 'html.parser')
|
soup = bs4.BeautifulSoup(f, 'html.parser')
|
||||||
|
Loading…
Reference in New Issue
Block a user