From 75d6b82453681b3f95b84bc7b3d76bcf6ee2ed29 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 11 Oct 2014 23:32:50 +0200 Subject: [PATCH 01/11] added an importer.py for importing bookmarks n stuff currently supports chromium bookmarks usage: in chromium: export your bookmarks to html file (bookmark manager) ./importer.py chromium bookmarks_10_11_14.html >> ~/.config/qutebrowser/quickmarks --- scripts/importer.py | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 scripts/importer.py diff --git a/scripts/importer.py b/scripts/importer.py new file mode 100755 index 000000000..8cf28b5a4 --- /dev/null +++ b/scripts/importer.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +# Copyright 2014 Claude (longneck) + +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +import argparse + + + +def main(): + args = get_args() + if args.browser == 'chromium': + import_chromium(args.bookmarks) + +def get_args(): + """Get the argparse parser.""" + parser = argparse.ArgumentParser("usage: importer.py") + parser.add_argument('browser', help="Which browser?") + parser.add_argument('bookmarks', help="Bookmarks file") + args = parser.parse_args() + return args + +def import_chromium(bookmarks_file): + import codecs + from bs4 import BeautifulSoup + + soup = BeautifulSoup(codecs.open(bookmarks_file, encoding='utf-8')) + + html_tags = soup.findAll('a') + + bookmarks = [] + for tag in html_tags: + if tag['href'] not in bookmarks: + bookmarks.append(str(tag.string) + ' ' + str(tag['href'])) + + for bookmark in bookmarks: + print(bookmark) + +if __name__ == '__main__': + main() + From 111f7b6e60b384400f78cee01e14feca7abde19b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 12 Oct 2014 01:16:28 +0200 Subject: [PATCH 02/11] fixed a typo --- qutebrowser/browser/quickmarks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/browser/quickmarks.py b/qutebrowser/browser/quickmarks.py index d446e5799..5b2386533 100644 --- a/qutebrowser/browser/quickmarks.py +++ b/qutebrowser/browser/quickmarks.py @@ -21,7 +21,7 @@ Note we violate our general QUrl rule by storing url strings in the marks OrderedDict. This is because we read them from a file at start and write them -to a file on shutdown, so it makes semse to keep them as strings her.e +to a file on shutdown, so it makes semse to keep them as strings here. """ import functools From f9b4dbc9cba4bc9af1db86b9f506fd6c85b4fd34 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 15 Oct 2014 06:15:50 +0200 Subject: [PATCH 03/11] importer: Use choices=... for argparse --- scripts/importer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/importer.py b/scripts/importer.py index 8cf28b5a4..73d9b25be 100755 --- a/scripts/importer.py +++ b/scripts/importer.py @@ -29,7 +29,8 @@ def main(): def get_args(): """Get the argparse parser.""" parser = argparse.ArgumentParser("usage: importer.py") - parser.add_argument('browser', help="Which browser?") + parser.add_argument('browser', help="Which browser?", choices=['chromium'], + metavar='browser') parser.add_argument('bookmarks', help="Bookmarks file") args = parser.parse_args() return args From abab935ca8375af703f56a020ce46cc170c9ffaa Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 15 Oct 2014 06:16:12 +0200 Subject: [PATCH 04/11] importer: Whitespace cleanup --- scripts/importer.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/importer.py b/scripts/importer.py index 73d9b25be..b57afd964 100755 --- a/scripts/importer.py +++ b/scripts/importer.py @@ -17,8 +17,8 @@ # You should have received a copy of the GNU General Public License # along with qutebrowser. If not, see . -import argparse +import argparse def main(): @@ -26,6 +26,7 @@ def main(): if args.browser == 'chromium': import_chromium(args.bookmarks) + def get_args(): """Get the argparse parser.""" parser = argparse.ArgumentParser("usage: importer.py") @@ -35,6 +36,7 @@ def get_args(): args = parser.parse_args() return args + def import_chromium(bookmarks_file): import codecs from bs4 import BeautifulSoup @@ -51,6 +53,6 @@ def import_chromium(bookmarks_file): for bookmark in bookmarks: print(bookmark) + if __name__ == '__main__': main() - From 78d5532227c77f3e98b25b89c23a0fff7502024c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 15 Oct 2014 06:16:42 +0200 Subject: [PATCH 05/11] importer: Use built-in open --- scripts/importer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/importer.py b/scripts/importer.py index b57afd964..ca67ebd04 100755 --- a/scripts/importer.py +++ b/scripts/importer.py @@ -38,10 +38,9 @@ def get_args(): def import_chromium(bookmarks_file): - import codecs from bs4 import BeautifulSoup - soup = BeautifulSoup(codecs.open(bookmarks_file, encoding='utf-8')) + soup = BeautifulSoup(open(bookmarks_file, encoding='utf-8')) html_tags = soup.findAll('a') From 2d7ea2e1fac46d9440fec3e861b54baf9a595ad7 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 15 Oct 2014 06:17:00 +0200 Subject: [PATCH 06/11] importer: Import cleanup --- scripts/importer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/importer.py b/scripts/importer.py index ca67ebd04..7fbe94c96 100755 --- a/scripts/importer.py +++ b/scripts/importer.py @@ -38,9 +38,9 @@ def get_args(): def import_chromium(bookmarks_file): - from bs4 import BeautifulSoup + import bs4 - soup = BeautifulSoup(open(bookmarks_file, encoding='utf-8')) + soup = bs4.BeautifulSoup(open(bookmarks_file, encoding='utf-8')) html_tags = soup.findAll('a') From 7731547d80e1ecb4d8ad1dc019d07d0a48d6575c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 15 Oct 2014 06:17:52 +0200 Subject: [PATCH 07/11] importer: Clean up string formatting --- scripts/importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/importer.py b/scripts/importer.py index 7fbe94c96..812e68f0c 100755 --- a/scripts/importer.py +++ b/scripts/importer.py @@ -47,7 +47,7 @@ def import_chromium(bookmarks_file): bookmarks = [] for tag in html_tags: if tag['href'] not in bookmarks: - bookmarks.append(str(tag.string) + ' ' + str(tag['href'])) + bookmarks.append('{tag.string} {tag[href]}'.format(tag=tag)) for bookmark in bookmarks: print(bookmark) From 64891863426ec926890a5735964fe8bde9b64591 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 15 Oct 2014 06:18:43 +0200 Subject: [PATCH 08/11] importer: Add docstrings. --- scripts/importer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/importer.py b/scripts/importer.py index 812e68f0c..f8d193d71 100755 --- a/scripts/importer.py +++ b/scripts/importer.py @@ -22,6 +22,7 @@ import argparse def main(): + """Main entry point.""" args = get_args() if args.browser == 'chromium': import_chromium(args.bookmarks) @@ -38,6 +39,7 @@ def get_args(): def import_chromium(bookmarks_file): + """Import bookmarks from a HTML file generated by Chromium.""" import bs4 soup = bs4.BeautifulSoup(open(bookmarks_file, encoding='utf-8')) From ea332d65ea3de1f0e5862485cd32b6e342131112 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 15 Oct 2014 06:19:15 +0200 Subject: [PATCH 09/11] importer: Fix printing of usage --- scripts/importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/importer.py b/scripts/importer.py index f8d193d71..8cab2c0a8 100755 --- a/scripts/importer.py +++ b/scripts/importer.py @@ -30,7 +30,7 @@ def main(): def get_args(): """Get the argparse parser.""" - parser = argparse.ArgumentParser("usage: importer.py") + parser = argparse.ArgumentParser() parser.add_argument('browser', help="Which browser?", choices=['chromium'], metavar='browser') parser.add_argument('bookmarks', help="Bookmarks file") From 2874cdea222d239607c2e71f4b93c7cdc41f1289 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 15 Oct 2014 06:20:54 +0200 Subject: [PATCH 10/11] importer: Add module docstring --- scripts/importer.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/importer.py b/scripts/importer.py index 8cab2c0a8..1a22dff91 100755 --- a/scripts/importer.py +++ b/scripts/importer.py @@ -18,6 +18,12 @@ # along with qutebrowser. If not, see . +"""Tool to import data from other browsers. + +Currently only importing bookmarks from Chromium is supported. +""" + + import argparse From 7adf7563267ebac7e82aa4cb57b82260a01223fd Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 15 Oct 2014 06:24:45 +0200 Subject: [PATCH 11/11] importer: Add help message about Chromium --- scripts/importer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/importer.py b/scripts/importer.py index 1a22dff91..80133411f 100755 --- a/scripts/importer.py +++ b/scripts/importer.py @@ -36,7 +36,9 @@ def main(): def get_args(): """Get the argparse parser.""" - parser = argparse.ArgumentParser() + 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'], metavar='browser') parser.add_argument('bookmarks', help="Bookmarks file")