Created
December 22, 2022 06:17
-
-
Save deep5050/ec69168b3eb9ae91087f211f783cca15 to your computer and use it in GitHub Desktop.
github workflow to download bing wallpapers daily
This file contains hidden or 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: Bing Wallpaper Download | |
on: | |
schedule: | |
- cron: "0 0 * * *" | |
jobs: | |
download_wallpaper: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install requests | |
- name: Download wallpaper | |
run: | | |
import requests | |
import json | |
import datetime | |
# Get the JSON data from the Bing Wallpaper API | |
response = requests.get('https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1') | |
data = response.json() | |
# Extract the URL of the wallpaper image from the JSON data | |
image_url = "https://www.bing.com" + data['images'][0]['url'] | |
# Download the image | |
response = requests.get(image_url) | |
# Get the current date | |
today = datetime.datetime.now().strftime("%Y-%m-%d") | |
# Save the image to a file | |
with open(f'wallpapers/{today}.jpg', 'wb') as f: | |
f.write(response.content) | |
- name: Commit and push changes | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
git add wallpapers | |
git commit -m "Add wallpaper for $ today" | |
git push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment