Created
October 31, 2024 18:57
-
-
Save stefanv/0dfe50a052e2a8ce9ee51685a53ef453 to your computer and use it in GitHub Desktop.
Import Omnivore reading list into Wallabag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Convert exported Omnivore reading list to Wallabag v2 JSON format. | |
This is by no means well checked or perfect, but it should serve as a start for further efforts. | |
It got my list of articles imported into Wallabag, which is all I wanted. | |
""" | |
import json | |
import csv | |
from datetime import datetime | |
import glob | |
def convert_to_wallabag_json(omnivore_data): | |
wallabag_entries = [] | |
for item in omnivore_data: | |
entry = { | |
"is_archived": 1 if item["state"] == "Archived" else 0, | |
"is_starred": 0, | |
"tags": item["labels"], | |
"is_public": False, | |
"id": None, # Wallabag will assign a new ID | |
"title": item["title"], | |
"url": item["url"], | |
"given_url": item["url"], | |
"content": item.get("description", ""), # Use description as content if available | |
"created_at": datetime.fromisoformat(item["savedAt"].replace('Z', '+00:00')).strftime("%Y-%m-%d %H:%M:%S"), | |
"updated_at": datetime.fromisoformat(item["updatedAt"].replace('Z', '+00:00')).strftime("%Y-%m-%d %H:%M:%S"), | |
"published_by": [], | |
"annotations": [], | |
"domain_name": item["url"].split("//")[-1].split("/")[0], | |
"preview_picture": item.get("thumbnail", "") | |
} | |
if item["publishedAt"] is not None: | |
entry["published_at"] = datetime.fromisoformat(item["publishedAt"].replace('Z', '+00:00')).strftime("%Y-%m-%d %H:%M:%S") | |
wallabag_entries.append(entry) | |
return wallabag_entries | |
# Read Omnivore JSON data | |
omnivore_data = [] | |
for f in glob.glob('metadata_*.json'): | |
with open(f, 'r') as f: | |
omnivore_data.extend(json.load(f)) | |
# Convert to Wallabag format | |
wallabag_data = convert_to_wallabag_json(omnivore_data) | |
# Write to JSON file | |
with open('wallabag_import.json', 'w', encoding='utf-8') as f: | |
json.dump(wallabag_data, f, ensure_ascii=False, indent=2) | |
print("Conversion complete. Output saved to 'wallabag_import.json'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment