2025-02-01 00:33:54 -06:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import json
|
|
|
|
from html import unescape
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2025-02-02 14:28:28 -06:00
|
|
|
with open("/home/jas/downloads/mastodon-archive/outbox.json", "r") as jf:
|
2025-02-01 00:33:54 -06:00
|
|
|
json_data = json.load(jf)
|
|
|
|
|
2025-02-02 14:28:28 -06:00
|
|
|
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()
|
2025-02-01 00:33:54 -06:00
|
|
|
|
2025-02-02 14:28:28 -06:00
|
|
|
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}")
|
2025-02-01 00:33:54 -06:00
|
|
|
print("#+BEGIN_EXPORT html")
|
2025-02-02 14:28:28 -06:00
|
|
|
if type(content) is str:
|
|
|
|
print(unescape(content))
|
2025-02-01 00:33:54 -06:00
|
|
|
print("#+END_EXPORT")
|
2025-02-02 14:28:28 -06:00
|
|
|
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()
|
2025-02-01 00:33:54 -06:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|