import json import sqlite3 import os import urllib.parse dir = os.listdir('./data') # To add to db: Title, URL, Domain # print(dir) all_bookmarks = [] def check_domain(all_bookmarks, domain): present = False for item in all_bookmarks: if domain == item['domain']: present = True return present def parse_object(object_): for child in object_['children']: if 'children' in child: parse_object(child) else: if child['type'] == 'text/x-moz-place' and child['title'] != 'Recent Tags' and child['title'] != 'Most Visited': dropped = '' url = child['uri'] if 'https' in child['uri']: dropped = child['uri'].removeprefix('https://') else: dropped = child['uri'].removeprefix('http://') # print('Dropped: ' + dropped) if 'about:reader' in dropped: # print('Firefox Reader bookmarked!') dropped = dropped.removeprefix('about:reader?url=') dropped = dropped.replace('%3A', ':').replace('%2F', '/') url = dropped # print(dropped) elif "read://" in dropped: # print('Edge Reader bookmarked!') dropped = dropped.split('?url=')[1] dropped = dropped.replace('%3A', ':').replace('%2F', '/') url = dropped # print(dropped) url = dropped if len(url.split('/')) == 1: print(child['uri']) print(child) domain = url.split('/')[0] new_dict = { 'url': url, 'title': child['title'] } if check_domain(all_bookmarks, domain): for item in all_bookmarks: if domain == item['domain'] and new_dict not in item['bookmarks']: item['bookmarks'].append(new_dict) else: new_domain = { 'domain': domain, 'bookmarks': [] } new_domain['bookmarks'].append(new_dict) all_bookmarks.append(new_domain) # Check if domain already in -> otherwise # print('
Title: {} '.format(url, child['title'])) for file in dir: # print('File: ' + file) with open('./data/' + file) as opened: object_ = json.load(opened) parse_object(object_) for item in all_bookmarks: link = '' for bookmark in item['bookmarks']: link = link + '''