From 47d5f7231ab5afcfa56117b39cee63c8cda26807 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Mon, 21 Oct 2024 16:47:02 +0100 Subject: [PATCH 1/2] Add workflow to pull in blog post entries. Signed-off-by: Andy Piper --- .github/workflows/update_readme.yml | 45 +++++++++++++++++++++++ profile/README.md | 11 ++++-- update_readme.py | 56 +++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/update_readme.yml create mode 100644 update_readme.py diff --git a/.github/workflows/update_readme.yml b/.github/workflows/update_readme.yml new file mode 100644 index 0000000..82ac5f2 --- /dev/null +++ b/.github/workflows/update_readme.yml @@ -0,0 +1,45 @@ +name: Update README with recent blog posts + +on: + schedule: + - cron: '0 */12 * * *' # Run every 12 hours + workflow_dispatch: + push: + +jobs: + update-readme: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.3 + with: + repository: ${{ github.repository }} + fetch-depth: 1 + - name: Set up Python + uses: actions/setup-python@v5.1.0 + with: + python-version: '3.12' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install feedparser + - name: Update README + run: python update_readme.py + - name: Check for changes + id: git-check + run: | + git status + git diff + git diff --quiet || echo "changes=true" >> $GITHUB_OUTPUT + - name: Commit changes + if: steps.git-check.outputs.changes == 'true' + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add profile/README.md + git commit -m "Updated README with latest blog posts" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: No changes + if: steps.git-check.outputs.changes != 'true' + run: echo "No changes to commit" diff --git a/profile/README.md b/profile/README.md index 28aa0ca..b7d5309 100644 --- a/profile/README.md +++ b/profile/README.md @@ -4,7 +4,7 @@ Mastodon -Mastodon is a free, open-source social network server based on ActivityPub where users can follow friends and discover new ones. All Mastodon servers are interoperable as a federated network. +Mastodon is a free, open source social network server based on ActivityPub, where users can follow friends and discover new ones. All Mastodon servers are interoperable as a federated network. - [Project homepage 🐘](https://joinmastodon.org) - [Support the development via Patreon](https://www.patreon.com/mastodon) @@ -13,6 +13,11 @@ Mastodon is a free, open-source social network server based on ActivityPub where - [Roadmap](https://joinmastodon.org/roadmap) - [Blog](https://blog.joinmastodon.org) +## Recent blog posts + + + + ## Reporting issues / contributing code - Please read the [Contributing to Mastodon](https://github.com/mastodon/.github/blob/main/CONTRIBUTING.md) guide @@ -23,10 +28,10 @@ Mastodon is a free, open-source social network server based on ActivityPub where ## Community participation -Participation is via the [Mastodon Code of Conduct](https://github.com/mastodon/.github/blob/main/CODE_OF_CONDUCT.md) +Participation is subject to the [Mastodon Code of Conduct](https://github.com/mastodon/.github/blob/main/CODE_OF_CONDUCT.md) ## Follow us -Find us on Mastodon 🙂 +Find us on Mastodon! 🙂 [![Mastodon](https://img.shields.io/badge/Mastodon%20-%231DA1F2.svg?&style=flat-square&logo=mastodon&logoColor=white&color=6364FF)](https://mastodon.social/@mastodon) [![MastodonEngineering](https://img.shields.io/badge/MastodonEngineering%20-%231DA1F2.svg?&style=flat-square&logo=mastodon&logoColor=white&color=6364FF)](https://mastodon.social/@MastodonEngineering) diff --git a/update_readme.py b/update_readme.py new file mode 100644 index 0000000..1ef2745 --- /dev/null +++ b/update_readme.py @@ -0,0 +1,56 @@ +import feedparser +from datetime import datetime + +# Fetch the RSS feed +feed_url = "https://blog.joinmastodon.org/index.xml" +feed = feedparser.parse(feed_url) + + +# Function to format the publication date +def format_date(published): + try: + # Parse the published date from the entry + parsed_date = datetime(*published[:6]) + return parsed_date.strftime("%Y-%m-%d") + except Exception as e: + # Return an empty string if date parsing fails + return "" + + +# Extract the latest 3 posts +max_posts = 3 +latest_posts = [] +for entry in feed.entries[:max_posts]: + title = entry.title + link = entry.link + pub_date = format_date(entry.published_parsed) # Format the publication date + # Add the post with the title, publication date, and optionally the summary + latest_posts.append(f"- :newspaper: [{title}]({link}) - *{pub_date}*") + +with open("profile/README.md", "r") as readme_file: + readme_content = readme_file.readlines() + +start_marker = "\n" +end_marker = "\n" + +# Ensure the markers are present in the README.md +if start_marker not in readme_content or end_marker not in readme_content: + print("Markers not found in README.md. Please ensure you have the markers.") + exit(1) + +# Get the content before and after the markers +start_index = readme_content.index(start_marker) + 1 +end_index = readme_content.index(end_marker) + +# Create the new content between the markers +new_readme_content = ( + readme_content[:start_index] + + [f"{post}\n" for post in latest_posts] + + readme_content[end_index:] +) + +# Write the new content back to README.md +with open("profile/README.md", "w") as readme_file: + readme_file.writelines(new_readme_content) + +print("profile/README.md has been updated with the latest blog posts.") From c59a305cb72e0b37acbc21ce1526b35321cef06c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 21 Oct 2024 15:47:27 +0000 Subject: [PATCH 2/2] Updated README with latest blog posts --- profile/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/profile/README.md b/profile/README.md index b7d5309..c930bf3 100644 --- a/profile/README.md +++ b/profile/README.md @@ -16,6 +16,9 @@ Mastodon is a free, open source social network server based on ActivityPub, wher ## Recent blog posts +- :newspaper: [Trunk & Tidbits, September 2024](https://blog.joinmastodon.org/2024/10/trunk-tidbits-september-2024/) - *2024-10-10* +- :newspaper: [Mastodon 4.3](https://blog.joinmastodon.org/2024/10/mastodon-4.3/) - *2024-10-08* +- :newspaper: [Trunk & Tidbits, August 2024](https://blog.joinmastodon.org/2024/09/trunk-tidbits-august-2024/) - *2024-09-09* ## Reporting issues / contributing code