Skip to content

Commit

Permalink
poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
sowoi committed May 3, 2023
1 parent ab5fcfc commit 9105ce3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# syntax=docker/dockerfile:1
FROM python:latest
RUN apt update && apt install python3-dev gcc -y
RUN useradd -rm -d /home/appuser -s /bin/bash -g root -G sudo -u 1001 appuser
COPY requirements.txt /home/appuser/requirements.txt
COPY entrypoint.sh /home/appuser/entrypoint.sh
RUN chmod +x /home/appuser/entrypoint.sh
RUN apt update && apt install python3-dev gcc -y curl
RUN useradd --create-home appuser
WORKDIR /app
USER appuser
RUN mkdir -p /home/appuser/.local/share/pypoetry
RUN curl -sSL https://install.python-poetry.org | python3 - --preview
ENV PATH="/home/appuser/.local/bin:${PATH}"
WORKDIR /home/appuser
RUN pip3 install -r requirements.txt
ENV PATH=/home/appuser/.local/bin:$PATH
COPY webhookfromghost.ini /home/appuser/webhookfromghost.ini
COPY webhookfromghost.py /home/appuser/webhookfromghost.py
COPY wsgi.py /home/appuser/wsgi.py
COPY --chown=appuser:appuser pyproject.toml webhookfromghost.ini webhookfromghost.py poetry.lock wsgi.py requirements.txt entrypoint.sh /home/appuser/
RUN poetry config virtualenvs.in-project true \
&& poetry install --no-interaction --no-ansi
EXPOSE 5000/tcp
RUN chmod +x /home/appuser/entrypoint.sh
ENTRYPOINT ["/home/appuser/entrypoint.sh"]
4 changes: 3 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ export WEBHOOK_SECRET=$(cat /run/secrets/WEBHOOK_SECRET)
export MASTODON_ACCESS_TOKEN=$(cat /run/secrets/MASTODON_ACCESS_TOKEN)
export MASTODON_BASE_URL=$(cat /run/secrets/MASTODON_BASE_URL)
export TRUSTED_PROXIES=$(cat /run/secrets/TRUSTED_PROXIES)
echo "Starting poetry shell"
echo `poetry --version`
echo "Starting uwsgi"
uwsgi --ini /home/appuser/webhookfromghost.ini
poetry run uwsgi --ini /home/appuser/webhookfromghost.ini
20 changes: 10 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
blurhash==1.1.4
certifi==2022.12.7
charset-normalizer==3.1.0
charset-normalizer==2.1.1
click==8.1.3
decorator==5.1.1
Flask==2.3.2
Flask==2.2.2
idna==3.4
importlib-metadata==6.6.0
importlib-metadata==6.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
Mastodon.py==1.8.1
MarkupSafe==2.1.1
Mastodon.py==1.8.0
python-dateutil==2.8.2
python-magic==0.4.27
pytz==2023.3
requests==2.28.2
pytz==2022.7
requests==2.28.1
six==1.16.0
urllib3==1.26.15
urllib3==1.26.13
uWSGI==2.0.21
Werkzeug==2.2.3
zipp==3.15.0
Werkzeug==2.2.2
zipp==3.11.0
19 changes: 11 additions & 8 deletions webhookfromghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ def get_webhook():
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
ghostPost = request.json["post"]["current"]
ghostTitle = str(ghostPost["title"])
ghostURL = str(ghostPost["url"])
ghostExcerpt = str(ghostPost.get("custom_excerpt", ""))
ghostTags = ghostPost.get("tags", [])
ghostToot = f"{ghostTitle}\n{ghostExcerpt}\n{ghostURL}"


hashtags = tags_to_mastodon_has(ghostTags)
print("Adding Hashtags: ", hashtags)
ghostToot = ghostTitle + "\n" + ghostExcerpt + "\n" + ghostURL + "\n" + hashtags
ghostToot = f"{ghostToot}\n{hashtags}"
print("Creating toot: ", ghostToot)
mastodon = Mastodon(access_token = access_token, api_base_url = base_url, debug_requests=True)
mastodon.toot(ghostToot)
Expand All @@ -33,6 +35,7 @@ def get_webhook():

def tags_to_mastodon_has(ghostTags):
# convert ghost cms tags to mastodon hashtags
return " ".join(f"#{tag['name']}" for tag in ghostTags)
tagsList = ''
for tags in ghostTags:
print(tags["name"])
Expand All @@ -58,10 +61,10 @@ def limit_remote_addr():
def check_access():
print("Checking token and URL...")
# check if token and url are set
if access_token == None:
if access_token is None:
print("Missing Mastodon access token")
raise RuntimeError('Missing Mastodon access token')
elif base_url == None:
elif base_url is None:
print("Missing Mastodon base URL")
raise RuntimeError('Missing Mastodon base URL')
else:
Expand Down

0 comments on commit 9105ce3

Please sign in to comment.