Finish and use this
This commit is contained in:
parent
48a51ba971
commit
195ada61f6
@ -1,26 +1,46 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from pandas import json_normalize
|
|
||||||
import json
|
import json
|
||||||
from html import unescape
|
from html import unescape
|
||||||
|
|
||||||
|
|
||||||
def main():
|
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)
|
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():
|
for item in sorted(
|
||||||
print(f"*** {item[1]["object.published"]}")
|
json_data["orderedItems"], key=json_data["orderedItems"].index, reverse=True
|
||||||
if type(item[1]["object.content"]) is str:
|
):
|
||||||
print("#+BEGIN_QUOTE")
|
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("#+BEGIN_EXPORT html")
|
||||||
print(unescape(item[1]["object.content"]))
|
if type(content) is str:
|
||||||
|
print(unescape(content))
|
||||||
print("#+END_EXPORT")
|
print("#+END_EXPORT")
|
||||||
if item[1]["object.attachment"]:
|
if attachment:
|
||||||
if type(item[1]["object.attachment"]) is list:
|
if attachment.get("name"):
|
||||||
for i in item[1]["object.attachment"]:
|
print(f"#+CAPTION: {attachment.get('name')}")
|
||||||
|
print(
|
||||||
|
f"[[https://files.hyperreal.coffee/mastodon_20240216-20250131/{attachment.get('url')}]]"
|
||||||
|
)
|
||||||
|
print("-----")
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user