Files
hooky/main.py
2025-09-26 10:40:12 -04:00

73 lines
1.9 KiB
Python

from flask import Flask, request
import httpx
app = Flask(__name__)
def populate_webhook_lookup():
lookup = {}
with open("lookup.txt", "r") as file:
for line in file:
split_line = line.rstrip().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"),
"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","simbob"),
"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):
lookup = populate_webhook_lookup()
webhook = lookup.get(uuid)
print(lookup)
ghost_payload = request.get_json()
print(ghost_payload)
discord_payload = convert_ghost_to_discord(ghost_payload)
httpx.post(webhook, data=discord_payload)
return 200
def main():
print("Hello from webhookproxy!")
with open("lookup.txt", "r") as file:
for line in file:
print(line.split(','))
if __name__ == "__main__":
main()