diff --git a/python/publish_mastodon_archive.py b/python/publish_mastodon_archive.py index 6446b71..14238ff 100644 --- a/python/publish_mastodon_archive.py +++ b/python/publish_mastodon_archive.py @@ -1,26 +1,46 @@ #!/usr/bin/env python3 -from pandas import json_normalize import json from html import unescape def main(): - with open("/home/jas/downloads/outbox.json", "r") as jf: + with open("/home/jas/downloads/mastodon-archive/outbox.json", "r") as jf: json_data = json.load(jf) - flattened_df = json_normalize(json_data, record_path=["orderedItems"]) + print("#+TITLE: Mastodon posts archive from 2024-02-16 to 2025-01-31") + print("#+DATE: 2025-02-02") + print("#+TAGS[]: mastodon archives") + print("#+AUTHOR: hyperreal") + print("#+SLUG: mastodon_archive-20240216-20250131") + print("#+LAYOUT: post") + print() - for item in flattened_df.iterrows(): - print(f"*** {item[1]["object.published"]}") - if type(item[1]["object.content"]) is str: - print("#+BEGIN_QUOTE") + for item in sorted( + json_data["orderedItems"], key=json_data["orderedItems"].index, reverse=True + ): + if type(item.get("object")) is dict: + published = item.get("object").get("published") + content = item.get("object").get("content") + attachment = ( + item.get("object").get("attachment")[0] + if len(item.get("object").get("attachment")) >= 1 + else None + ) + + print(f"** {published}") print("#+BEGIN_EXPORT html") - print(unescape(item[1]["object.content"])) + if type(content) is str: + print(unescape(content)) print("#+END_EXPORT") - if item[1]["object.attachment"]: - if type(item[1]["object.attachment"]) is list: - for i in item[1]["object.attachment"]: + if attachment: + if attachment.get("name"): + print(f"#+CAPTION: {attachment.get('name')}") + print( + f"[[https://files.hyperreal.coffee/mastodon_20240216-20250131/{attachment.get('url')}]]" + ) + print("-----") + print() if __name__ == "__main__":