From 4d638bce9996a83a140e296db6a95077bd320d48 Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Fri, 26 Sep 2025 10:03:53 -0400 Subject: [PATCH] yeet --- .gitignore | 10 +++++++ .python-version | 1 + Dockerfile | 13 +++++++++ README.md | 0 docker-compose.yml | 12 +++++++++ main.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 7 +++++ 7 files changed, 109 insertions(+) create mode 100644 .gitignore create mode 100644 .python-version create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100644 main.py create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..505a3b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Python-generated files +__pycache__/ +*.py[oc] +build/ +dist/ +wheels/ +*.egg-info + +# Virtual environments +.venv diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..24ee5b1 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.13 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..92f9662 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.13-slim + +WORKDIR /app + +COPY pyproject.toml . +COPY main.py . +COPY lookup.txt . + +RUN pip install flask httpx + +EXPOSE 5000 + +CMD ["python", "-m", "flask", "--app", "main", "run", "--host=0.0.0.0"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..be09468 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.8' + +services: + webhookproxy: + build: . + ports: + - "5000:5000" + environment: + - FLASK_ENV=production + volumes: + - ./lookup.txt:/app/lookup.txt:ro + restart: unless-stopped \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..fdb741b --- /dev/null +++ b/main.py @@ -0,0 +1,66 @@ +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("/: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() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d497921 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[project] +name = "webhookproxy" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.13" +dependencies = []