bookmarks.py 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python
  2. # I got the json file by clicking backup bookmarks in palemoon. Maybe
  3. # this can work generally in firefox browsers idk.
  4. import json
  5. backup = "c:\\sgz_Pro\\Hobbys\\Writing\\Org\\bookmarks-2022-07-12.json"
  6. with open(backup, encoding="utf-8") as f:
  7. text = f.read()
  8. json_stuff = json.loads(text)
  9. with open("index.html","w") as f:
  10. f.write("<h1>Bookmarks Toolbar</h1>")
  11. for i, bookmark in enumerate(json_stuff["children"][1]["children"]):
  12. print(i)
  13. if bookmark["type"] == "text/x-moz-place":
  14. with open("index.html","a") as f:
  15. if bookmark["title"] != "":
  16. f.write(f"\n<p><a href='{bookmark['uri']}'>{bookmark['title']}</a></p>")
  17. else:
  18. f.write(f"\n<p><a href='{bookmark['uri']}'>{bookmark['uri']}</a></p>")
  19. elif bookmark["type"] == "text/x-moz-place-separator":
  20. with open("index.html","a") as f:
  21. f.write("\n<hr>")
  22. elif bookmark["type"] == "text/x-moz-place-container":
  23. with open("index.html","a") as f:
  24. f.write(f"\n<h2>{bookmark['title']}</h2>\n<ul>")
  25. for item in bookmark["children"]:
  26. f.write(f"<li><a href='{item['uri']}'>{item['title'].encode('utf-8').decode('ascii','ignore')}</a></li>")
  27. f.write("\n</ul>")