Initial commit

This commit is contained in:
mustard 2026-02-22 20:48:18 +01:00
commit a373f897c6
4 changed files with 102 additions and 0 deletions

7
LICENSE Normal file
View file

@ -0,0 +1,7 @@
Copyright (c) <year> <copyright holders>
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.

1
README.md Normal file
View file

@ -0,0 +1 @@
Simple script to parse bookmarks from exported json files, remove duplicate bookmarks, and organize them by domain. Outputs HTML.

0
data/.gitkeep Normal file
View file

94
main.py Normal file
View file

@ -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('</p> <a href="https://{}" target="_blank"> Title: {} </a>'.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 + '''
<li>
<a href="https://{0}" target="_blank"> {1} </a>
</li>
'''.format(bookmark['url'], bookmark['title'])
template = '''
<details>
<summary> {0} </summary>
<ol>
{1}
</ol>
</details>
'''.format(item['domain'], link)
print(template)