From a373f897c651e00943da43139cb0364c8044e0f9 Mon Sep 17 00:00:00 2001 From: mustard Date: Sun, 22 Feb 2026 20:48:18 +0100 Subject: [PATCH] Initial commit --- LICENSE | 7 ++++ README.md | 1 + data/.gitkeep | 0 main.py | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 data/.gitkeep create mode 100644 main.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3b4562c --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e13eeaf --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Simple script to parse bookmarks from exported json files, remove duplicate bookmarks, and organize them by domain. Outputs HTML. diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py new file mode 100644 index 0000000..e9b64ee --- /dev/null +++ b/main.py @@ -0,0 +1,94 @@ +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 + ''' +
  • + {1} +
  • + '''.format(bookmark['url'], bookmark['title']) + template = ''' +
    + {0} +
      + {1} +
    +
    + '''.format(item['domain'], link) + print(template)