Add wallabag2hoarder directory
This commit is contained in:
parent
b1c427067e
commit
bd04d5bbde
2 changed files with 98 additions and 0 deletions
46
wallabag2hoarder/convert_netscape.py
Executable file
46
wallabag2hoarder/convert_netscape.py
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from jinja2 import Template
|
||||
|
||||
# USAGE: ./convert.py file exportfile
|
||||
|
||||
if len(sys.argv) < 2 or not Path(sys.argv[1]).is_file():
|
||||
print("Please provide a file to import as the first argument.")
|
||||
sys.exit(1)
|
||||
|
||||
INPUT_FILE = Path(sys.argv[1])
|
||||
OUTPUT_FILE = (
|
||||
Path(sys.argv[2]) if len(sys.argv) > 2 else Path("exported_bookmarks.html")
|
||||
)
|
||||
print(f"[DEBUG]\ninput: {INPUT_FILE}\noutput: {OUTPUT_FILE}")
|
||||
|
||||
|
||||
# TODO: Timestamp does not get recognized and instead becomes 1970-01-01 - maybe needs unix ts?
|
||||
def generate_html(data):
|
||||
return Template("""<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
||||
<TITLE>Bookmarks</TITLE>
|
||||
<H1>Bookmarks</H1>
|
||||
<DL><p>
|
||||
{% for item in data %}
|
||||
<DT>
|
||||
<A HREF="{{ item.url }}" ADD_DATE="{{ item.created_at }}" TAGS="{{ item.tags }}">{{ item.title }}</A>
|
||||
</DT>
|
||||
{% endfor %}
|
||||
</DL><p>
|
||||
""").render(data=data)
|
||||
|
||||
|
||||
# Read JSON file
|
||||
with open(INPUT_FILE, "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
html_content = generate_html(data)
|
||||
|
||||
# Save or print HTML content
|
||||
with open(OUTPUT_FILE, "w") as f:
|
||||
f.write(html_content)
|
||||
Loading…
Add table
Add a link
Reference in a new issue