Files
hooky/main.py
2025-09-26 10:16:01 -04:00

67 lines
1.7 KiB
Python

from flask import Flask
app = Flask(__name__)
def populate_webhook_lookup():
lookup = {}
with open("./lookup.txt") as file:
for line in file:
split_line = line.split(",")
lookup[split_line[0]]: split_line[1]
return lookup
UUID_TO_WEBHOOK_LOOKUP = populate_webhook_lookup()
def convert_ghost_to_discord(ghost_payload):
post = ghost_payload.get("post").get("current")
return {
"embeds": [{
"title": post.get("title"),
"description": post.get("excerpt")[:200] + "...",
"url": f"https://torrtle.co/{post.get('slug')}",
"color": "0x00ff00",
"thumbnail": {
"url": post.get("feature_image")
},
"fields": [
{
"name": "Author",
"value": post.get("primary_author").get("name"),
"inline": True
},
{
"name": "Published",
"value": post.get("published_at"),
"inline": True,
}
],
}]
}
@app.route("/")
def home():
return "This is a silly web util that converts the Ghost webhook payloads to Discord payloads"
@app.route("/hook/<uuid", methods=["POST"])
def convert(uuid):
webhook = UUID_TO_WEBHOOK_LOOKUP.get(uuid)
ghost_payload = request.get_json()
discord_payload = convert_ghost_to_discord(ghost_payload)
httpx.post(webhook, data=discord_payload)
return 200
def main():
print("Hello from webhookproxy!")
if __name__ == "__main__":
main()