5 ms·
I have an archive of my tweets from a year ago. Not sure if the format changed, but this makes an html file with the full text and images and vids. Format to ta
by acidburnNSA 3y ago
I have an archive of my tweets from a year ago. Not sure if the format changed, but this makes an html file with the full text and images and vids. Format to taste.
import datetime
import json
import os
import sys
out = sys.stdout
media = {}
for med in os.listdir("data/tweet_media"):
tid = med.split("-")[0]
exist = media.get(tid, [])
exist.append(med)
media[tid] = exist
out.write("<html><body>\n")
with open("data/tweet.js") as d:
vals = json.load(d)
for val in sorted(
vals,
key=lambda val: datetime.datetime.strptime(
val["tweet"]["created_at"], "%a %b %d %H:%M:%S %z %Y"
),
):
tweet = val["tweet"]
out.write("<div>\n")
out.write(f"<i>{tweet['created_at']}</i>\n")
for fname in media.get(tweet["id"], []):
if fname.endswith("mp4"):
out.write(
f'<video controls><source src="data/tweet_media/{fname}" type="video/mp4"></video>\n'
)
else:
out.write(f'<img src="data/tweet_media/{fname}"/>\n')
if "full_text" in tweet:
out.write(f'<p>{tweet["full_text"]}</p>\n')
out.write("</div>\n")
out.write("</body></html>\n")