Created
January 1, 2023 19:53
-
-
Save schlamar/ceb6e667f876fe93da7ce86b07c79ff3 to your computer and use it in GitHub Desktop.
Import Wallabag JSON to linkding
This file contains 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
import json | |
import requests | |
def transform_data(data: dict) -> dict: | |
return { | |
"url": data["url"], | |
"tag_names": data["tags"], | |
"unread": bool(data["is_archived"]), | |
} | |
def main(): | |
with open("All articles.json") as fobj: | |
data = json.load(fobj) | |
with requests.Session() as session: | |
session.headers["Authorization"] = "Token XXX" | |
for entry in reversed(data): | |
payload = transform_data(entry) | |
print(f"Importing {payload['url']}") | |
response = session.post( | |
"https://<url>/api/bookmarks/", | |
json=payload, | |
) | |
response.raise_for_status() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment