-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from webhookfromghost import app | ||
|
||
if __name__ == "__main__": | ||
app.run() |