diff --git a/.github/scripts/update_youtube.py b/.github/scripts/update_youtube.py new file mode 100644 index 0000000..e61ad54 --- /dev/null +++ b/.github/scripts/update_youtube.py @@ -0,0 +1,53 @@ +import urllib.request +import xml.etree.ElementTree as ET +import re + +CHANNEL_ID = "UCM4Zvt9DVqzAHJOJoCgcF_g" +RSS_URL = f"https://www.youtube.com/feeds/videos.xml?channel_id={CHANNEL_ID}" + +NS = { + "atom": "http://www.w3.org/2005/Atom", + "yt": "http://www.youtube.com/xml/schemas/2015", +} + +with urllib.request.urlopen(RSS_URL) as r: + root = ET.fromstring(r.read()) + +entry = root.find("atom:entry", NS) +title = entry.find("atom:title", NS).text +video_id = entry.find("yt:videoId", NS).text +embed_url = f"https://www.youtube.com/embed/{video_id}" + +block = ( + "\n" + f"

7Zeb's Newest Video is: {title}

\n" + f"

Watch it now!

\n" + f' \n' + " " +) + +with open("index.html", "r", encoding="utf-8") as f: + content = f.read() + +if "" not in content: + raise RuntimeError( + "Markers not found in index.html, add " + "and around the newest video block." + ) + +updated = re.sub( + r".*?", + block, + content, + flags=re.DOTALL, +) + +if updated == content: + print("No change.") +else: + with open("index.html", "w", encoding="utf-8") as f: + f.write(updated) + + print(f"Updated: {title} ({video_id})") diff --git a/.github/workflows/update-youtube.yml b/.github/workflows/update-youtube.yml new file mode 100644 index 0000000..97e6cc8 --- /dev/null +++ b/.github/workflows/update-youtube.yml @@ -0,0 +1,24 @@ + name: Update YouTube Section + + on: + schedule: + - cron: '0 */6 * * *' + workflow_dispatch: + + jobs: + update: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - name: Update YouTube section + run: python .github/scripts/update_youtube.py + + - name: Commit and push if changed + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add index.html + git diff --staged --quiet || (git commit -m "chore: auto-update YouTube section" && git push) diff --git a/index.html b/index.html index 267327b..67b4306 100644 --- a/index.html +++ b/index.html @@ -45,9 +45,11 @@

Welcome to 7Zeb's Website

Newest Video

-

7Zeb's Newest Video is: Installing Windows Sun Valley on real hardware

+ +

7Zeb's Newest Video is: iOS 27 Beta

Watch it now!

- + +

Currently 735 Subscribers (-1 Since Last Update)

Go to 7Zeb's Channel