Skip to content

Commit

Permalink
Skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
sowoi committed Nov 22, 2022
1 parent 15e85f0 commit 4a0af1f
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .secret
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Add_your_Access_Token_Here>
https://<Add_your_Mastodon_URL_Here>
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# syntax=docker/dockerfile:1
FROM python:3.8-slim-bullseye
RUN apt update && apt install python3-dev gcc -y
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY webhookfromghost.ini webhookfromghost.ini
COPY webhookfromghost.py webhookfromghost.py
COPY wsgi.py wsgi.py
EXPOSE 5000/tcp
CMD [ "uwsgi", "--ini", "webhookfromghost.ini" ]
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.1'

services:

ghostcms2mastodon:
image: okxo/ghostcms2mastodon:latest
restart: always
volumes:
- .secret:/.secret
restart: always
ports:
- 5000:5000
21 changes: 21 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
blurhash==1.1.4
certifi==2022.9.24
charset-normalizer==2.1.1
click==8.1.3
decorator==5.1.1
Flask==2.2.2
idna==3.4
importlib-metadata==5.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
Mastodon.py==1.6.3
python-dateutil==2.8.2
python-magic==0.4.27
pytz==2022.6
requests==2.28.1
six==1.16.0
urllib3==1.26.12
uWSGI==2.0.21
Werkzeug==2.2.2
zipp==3.10.0
9 changes: 9 additions & 0 deletions webhookfromghost.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[uwsgi]
module = wsgi:app
master = true
processes = 1
http-socket = :5000
socket = webhookfromghost.sock
chmod-socket = 600
vacuum = true
die-on-term = true
39 changes: 39 additions & 0 deletions webhookfromghost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from flask import Flask, request, abort
from mastodon import Mastodon

app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def get_webhook():
#print(request)
if request.method == 'POST':
try:
# extract post title, URL, excerpt and tags
ghostTitle = str(request.json["post"]["current"]["title"])
ghostURL = str(request.json["post"]["current"]["url"])
ghostExcerpt = str(request.json["post"]["current"]["custom_excerpt"])
ghostTags = request.json["post"]["current"]["tags"]
ghostToot = ghostTitle + "\n" + ghostExcerpt + "\n" + ghostURL

hashtags = tags_to_mastodon_has(ghostTags)
print("Adding Hashtags: ", hashtags)
ghostToot = ghostTitle + "\n" + ghostExcerpt + "\n" + ghostURL + "\n" + hashtags
print("Creating toot: ", ghostToot)
mastodon = Mastodon(access_token = '.secret', debug_requests=True)
mastodon.toot(ghostToot)
return 'success', 200
except:
raise
else:
abort(400)

def tags_to_mastodon_has(ghostTags):
# convert ghost cms tags to mastodon hashtags
tagsList = ''
#print(ghostTags)
for tags in ghostTags:
print(tags["name"])
tagsList += " #"+tags["name"]
return tagsList.lstrip()

if __name__ == '__main__':
app.run(host="0.0.0.0")
4 changes: 4 additions & 0 deletions wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from webhookfromghost import app

if __name__ == "__main__":
app.run()

0 comments on commit 4a0af1f

Please sign in to comment.