Skip to content

Instantly share code, notes, and snippets.

@Rayquaza01
Created March 15, 2024 05:27
Show Gist options
  • Select an option

  • Save Rayquaza01/6f4fe81cc127227e27d22b63f000ae8c to your computer and use it in GitHub Desktop.

Select an option

Save Rayquaza01/6f4fe81cc127227e27d22b63f000ae8c to your computer and use it in GitHub Desktop.
Picotron Mastodon Proof of Concept
#!/usr/bin/env python3
from textwrap import wrap
import requests
from markdownify import markdownify
from flask import Flask, request
app = Flask(__name__)
@app.route("/statuses")
def root():
url = "https://" + request.args.get("server") + "/api/v1/statuses/" + request.args.get("id")
res = requests.get(url)
js = res.json()
username = js["account"]["display_name"]
acct = js["account"]["acct"]
created_at = js["created_at"]
content = "\n".join(wrap(markdownify(js["content"]), width=96))
media = ""
for attachment in js["media_attachments"]:
if attachment["description"] is None:
attachment["description"] = "No alt text provided :("
media += "\n".join(wrap(attachment["description"], width=96)) + "\n\n"
response = username + " @" + acct + "\n" + created_at + "\n\n" + content + "\n\nAttachments\n" + media
return response
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
function _init()
server = ""
id = ""
api = fetch("http://localhost:5000/statuses?server=" .. server .. "&id=" .. id)
end
function _draw()
cls()
print(api)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment