示例#1
0
    def bookmarks(self):
        """
        Bookmarks data

        :return:
        """
        if not self.__bookmarks_json:
            LOGGER.debug(self.bookmarks_path)
            self.__bookmarks_json = parse(self.bookmarks_path)
        return self.__bookmarks_json
示例#2
0
            session.commit()
            if bookmark['children']:
                save2db(bookmark['children'], bookmark, folder)
        elif bookmark['type'] == 'bookmark':
            tags = bookmark.get('tags')
            icon_uri = bookmark.get('icon_uri')
            book = Bookmark(title=title, url=bookmark['url'],
                            add_date=add_date, icon=bookmark['icon'],
                            icon_uri=icon_uri, tags=tags)
            prev_db_folder.bookmarks.append(book)
            session.add(book)
            session.commit()


if __name__ == '__main__':
    bookmarks = bookmarks_parser.parse("/home/andriy/PycharmProjects/bookmarks2db/chrome_bookmarks.html")
    save2db(bookmarks)

    # move folder with all nested bookmarks and folders to other folder aster certain position
    folder_on_other = session.query(Folder).filter(Folder.title == 'folder on other').one()
    index = folder_on_other.path.index(folder_on_other.path[-1])
    move_to_first_level_folder = session.query(Folder).filter(Folder.title == 'First level bookmark bar folder').one()

    first_level_folders = session.query(Folder).filter(Folder.path.descendant_of(folder_on_other.path)).all()
    for folder in first_level_folders:
        path = folder.path[index:]
        folder.path = move_to_first_level_folder.path + path
        session.add(folder)

    first_level_parent = session.query(Folder).filter(Folder.id == move_to_first_level_folder.parent_id).one()
    first_level_parent.folders.insert(move_to_first_level_folder.position + 1, folder_on_other)
示例#3
0
            'Version': '1.0',
            'Type': 'Link',
            'Name': title,
            'URL': bookmark['url']
        }
    with open('{}/{}.desktop'.format(folder_name, title), 'w') as configfile:
        config.write(configfile)


def title2path(child, prev=None):
    for bookmark in child:
        if bookmark.get('children'):
            if prev:
                bookmark['title'] = '{}/{}'.format(prev['title'],
                                                   bookmark['title'])
            bookmark_folder_path = Path(bookmark['title'])
            if not bookmark_folder_path.exists():
                bookmark_folder_path.mkdir()
            if bookmark['children']:
                title2path(bookmark['children'], bookmark)
        elif bookmark['type'] == 'bookmark':
            create_bookmark(bookmark, prev['title'])


if __name__ == '__main__':
    bookmarks = bookmarks_parser.parse("example/chrome_bookmarks.html")
    p = Path('icons')
    if not p.exists():
        p.mkdir()
    title2path(bookmarks)
    consolidate.py <bookmarks-A> <bookmarks-B>
    consolidate.py (-h|--help)

Arguments:
    <bookmarks-A> Bookmarks HTML file A
    <bookmarks-B> Bookmarks HTML file B
    (-h|--help)   This information screen

"""

import bookmarks_parser
import docopt

from bookmarks_consolidator.bookmarks_consolidator import BookmarksConsolidator

if __name__ == "__main__":
    arguments = []
    try:
        # Parse arguments, use file docstring as a parameter definition
        arguments = docopt.docopt(str(__doc__))
    except docopt.DocoptExit as de:
        print(de)
        exit(1)

    # parse and load HTML bookmarks files
    bookmarks_a = bookmarks_parser.parse(arguments['<bookmarks-A>'])
    bookmarks_b = bookmarks_parser.parse(arguments['<bookmarks-B>'])

    bc = BookmarksConsolidator()
    res = bc.consolidate_bookmarks(bookmarks_a, bookmarks_b)
示例#5
0
def run():
    bookmarks = bookmarks_parser.parse("bookmarks2.html")
    pprint.pprint(bookmarks)
示例#6
0
def get_bookmark_tree(parsed_bookmarks):
    bookmarks_tree = bp.parse(parsed_bookmarks)
    return bookmarks_tree
示例#7
0
import json
import pathlib

import bookmarks_parser

tests_data_path = pathlib.Path(__file__).parent.resolve()
bookmarks_files = ["chrome_bookmarks", "firefox_bookmarks"]
for bookmarks_file in bookmarks_files:
    bookmarks = bookmarks_parser.parse(tests_data_path /
                                       f"{bookmarks_file}.html")
    with open(tests_data_path / f"{bookmarks_file}.json", "w",
              encoding="utf8") as fp:
        json.dump(bookmarks, fp, indent=2, ensure_ascii=False)