Assorted shell and Python scripts
at main 1.5 kB view raw
1#!/usr/bin/env python3 2 3import json 4from html import unescape 5 6 7def main(): 8 with open("/home/jas/downloads/mastodon-archive/outbox.json", "r") as jf: 9 json_data = json.load(jf) 10 11 print("#+TITLE: Mastodon posts archive from 2024-02-16 to 2025-01-31") 12 print("#+DATE: 2025-02-02") 13 print("#+TAGS[]: mastodon archives") 14 print("#+AUTHOR: hyperreal") 15 print("#+SLUG: mastodon_archive-20240216-20250131") 16 print("#+LAYOUT: post") 17 print() 18 19 for item in sorted( 20 json_data["orderedItems"], key=json_data["orderedItems"].index, reverse=True 21 ): 22 if type(item.get("object")) is dict: 23 published = item.get("object").get("published") 24 content = item.get("object").get("content") 25 attachment = ( 26 item.get("object").get("attachment") 27 if len(item.get("object").get("attachment")) >= 1 28 else None 29 ) 30 31 print(f"** {published}") 32 print("#+BEGIN_EXPORT html") 33 if type(content) is str: 34 print(unescape(content)) 35 print("#+END_EXPORT") 36 if attachment: 37 for item in attachment: 38 if item.get("name"): 39 print(f"#+CAPTION: {item.get('name')}") 40 print( 41 f"[[https://files.hyperreal.coffee/mastodon_20240216-20250131/{item.get('url')}]]" 42 ) 43 print("-----") 44 print() 45 46 47if __name__ == "__main__": 48 main()