Skip to content

Commit

Permalink
Add new_article.py script that parse files and send notification
Browse files Browse the repository at this point in the history
  • Loading branch information
ctmbl committed Nov 17, 2023
1 parent 401b779 commit e7974f7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,12 @@ jobs:
- name: 🚀 Upload
run: |
rsync --archive --stats --verbose --delete ./build/blog/* ${{ secrets.CI_USER_NAME }}@iscsc.fr:${{ secrets.STATIC_WEBSITE_PATH}}
notify:
runs-on: ubuntu-latest
steps:
# Finally notify of the new article (if any) on the iScsc discord server
- name: 📨 Notify on Discord
- name: 📑 Get changed files
uses: jitterbit/get-changed-files@v1
id: files
with:
format: space-delimited
#token: ${{ secrets.GITHUB_TOKEN }}
- name: Printing
- name: Print changed files...
run: |
echo "All:"
echo "${{ steps.files.outputs.all }}"
Expand All @@ -97,3 +91,7 @@ jobs:
echo "${{ steps.files.outputs.modified }}"
echo "Added+Modified:"
echo "${{ steps.files.outputs.added_modified }}"
- name: 📨 Notify on Discord
run: |
python3 -m pip install requests PyYAML
python3 ./scripts/new_article.py ${{ steps.files.outputs.added }}
25 changes: 25 additions & 0 deletions scripts/new_article.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
import re
import requests
import yaml

for file_path in sys.argv[1:]:
# Check that this is an article file
if re.match("^src/content/posts/.+\.md$", file_path):
# Read YAML Header
with open(file_path, "r") as f:
raw_txt = f.read()
data = yaml.safe_load(raw_txt.split("---")[1])

# Get rid of python objects, only keep basic types
for key in data:
if type(data[key]) not in [int, str, float, bool]:
data[key] = str(data[key])

# Add URL info
file_name = file_path.split("/")[-1][:-3]
data["url"] = f"https://iscsc.fr/posts/{file_name}"

# Finally send Data
requests.post("http://iscsc.fr:8001/new-blog", json=data)
print(file_path, file_name, data)

0 comments on commit e7974f7

Please sign in to comment.