72 lines
1.8 KiB
Python
72 lines
1.8 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)
|
|
ghost_payload = request.get_json()
|
|
discord_payload = convert_ghost_to_discord(ghost_payload)
|
|
|
|
r = httpx.post(webhook, json=discord_payload)
|
|
print(r)
|
|
|
|
return "yay"
|
|
|
|
|
|
|
|
def main():
|
|
print("Hello from webhookproxy!")
|
|
with open("lookup.txt", "r") as file:
|
|
for line in file:
|
|
print(line.split(','))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|