Skip to content

Fetch Climacell Forecast #829

Fetch Climacell Forecast

Fetch Climacell Forecast #829

name: Fetch Climacell Forecast
on:
workflow_dispatch:
schedule:
- cron: 0 12 * * *
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Fetching the weather forecast from Climacell
env:
CLIMACELL_API_KEY: ${{ secrets.CLIMACELL_API_KEY }}
run: |
FILE=./src/json/forecast.json
echo "Fetching today's forecast from Climacell..."
url="https://data.climacell.co/v4/timelines?apikey="$CLIMACELL_API_KEY$"&timesteps=1h&location=39.99,-75.58&fields=temperature,dewPoint&units=imperial"
response=$(curl -f "$url")
status=$?
if [ $status -eq 0 ]; then
echo $response > $FILE
echo "$FILE saved."
else
echo "curl exit code: ($status) $response"
exit $status
fi
- name: Committing changes to git
env:
GIT_OWNER_EMAIL: ${{ secrets.GIT_OWNER_EMAIL }}
PUSH_TOKEN: ${{ secrets.PUSH_TOKEN }}
run: |
git config user.email "$GIT_OWNER_EMAIL"
git config user.name "tikaro"
if [[ `git status --porcelain` ]]; then
git add .
git commit -a -m "Update forecast data from Climacell API"
git remote rm origin
git remote add origin https://tikaro:$PUSH_TOKEN@github.com/tikaro/sandex.git
git push origin HEAD:main
else
echo 'unable to detect any changes'
fi