Scrape Neovim Themes #12
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
name: Scrape Neovim Themes | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Run daily at midnight | |
workflow_dispatch: # Allow manual triggers | |
jobs: | |
scrape: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install requests beautifulsoup4 PyYAML | |
- name: Scrape themes | |
run: | | |
cat > scrape.py << 'EOF' | |
from bs4 import BeautifulSoup | |
import requests | |
import re | |
def scrape_themes(): | |
url = "https://dotfyle.com/neovim/colorscheme/top" | |
response = requests.get(url) | |
soup = BeautifulSoup(response.text, 'html.parser') | |
plugin_links = soup.find_all("a", href=re.compile(r"^/plugins/")) | |
with open("themes.lua", "w") as file: | |
for link in plugin_links: | |
file.write("\"") | |
file.write(link.get("href").replace("/plugins/", "")) | |
file.write("\"\n") | |
url = "https://dotfyle.com/neovim/colorscheme/top?page=2" | |
response = requests.get(url) | |
soup = BeautifulSoup(response.text, 'html.parser') | |
plugin_links = soup.find_all("a", href=re.compile(r"^/plugins/")) | |
with open("themes.lua", "a") as file: | |
for link in plugin_links: | |
file.write("\"") | |
file.write(link.get("href").replace("/plugins/", "")) | |
file.write("\"\n") | |
if __name__ == "__main__": | |
themes = scrape_themes() | |
EOF | |
python scrape.py | |
- name: Commit and push if changed | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "GitHub Action" | |
git add themes.lua | |
if ! git diff --cached --quiet; then | |
git commit -m "Update themes from GitHub Action" | |
git push | |
else | |
echo "No changes detected; skipping commit." | |
fi |