Skip to content

This project uses GitLab Actions to collect the weather then update to README.md

Notifications You must be signed in to change notification settings

huantt/weather-forecast

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Today's Weather

Hanoi, Vietnam - 17/09/2024

Heavy rain

Hour 00:0001:0002:0003:0004:0005:0006:0007:0008:0009:0010:0011:0012:0013:0014:0015:0016:0017:0018:0019:0020:0021:0022:0023:00
Weather
Condition Patchy rain nearbyPatchy rain nearbyLight rain showerPatchy rain nearbyLight rain showerPatchy light drizzlePatchy rain nearbyPatchy light drizzleLight rain showerPatchy light rainLight rain showerPatchy light rainModerate or heavy rain showerLight rain showerLight rain showerLight rain showerLight rain showerLight rain showerLight rain showerPatchy rain nearbyClearPatchy light drizzlePatchy rain nearbyPatchy rain nearby
Temperature 26.1 °C26 °C25.8 °C25.2 °C25 °C24.9 °C24.7 °C25.6 °C27.1 °C28.7 °C30.2 °C30.6 °C31 °C30.9 °C30.8 °C30.9 °C29.9 °C28.6 °C27.7 °C27.3 °C29.2 °C26.5 °C26.2 °C26 °C
Wind 3.2 kph4.7 kph6.8 kph9 kph9.7 kph10.1 kph11.2 kph13.3 kph14 kph16.2 kph16.2 kph13.7 kph11.9 kph11.2 kph9.7 kph9.7 kph8.6 kph7.2 kph7.2 kph7.6 kph8.6 kph9.4 kph9.7 kph9.7 kph

Weather For Next 3 days

Date 17/09/202418/09/202419/09/2024
Weather
Condition Heavy rainHeavy rainModerate rain
Temperature 24.7 - 31 °C24.6 - 30 °C23.8 - 33 °C
Wind 16.2 kph11.2 kph17.3 kph

Updated at: 2024-09-17T13:30:44Z

GitHub Actions: Embed up-to-date Weather in your README

View

You can easily embed tables in your README.md using GitHub Actions by following these simple steps:

Step 1: In your repository, create a file named README.md.template.

Step 2: Write anything you want within the README.md.template file.

Step 3: Embed one of the following entities within your README.md.template:

  • Today's Weather Table:
{{ template "hourly-table" $.TodayWeather.HourlyWeathers }}
  • Daily Weather Table:
{{ template "daily-table" .Weathers }}
  • Updated at:
{{ formatTime .UpdatedAt }}

If you are familiar with Go templates, you have access to the root variable, which includes the following fields:

  • Weathers: An array of daily Weather. You can view the Weather struct definition in model/weather.go.
  • UpdatedAt: This field contains the timestamp in the format of time.Date.

Step 4: Register Github Action

  • Create a file .github/workflows/update-weather.yml in your repository.
name: "Cronjob"
on:
schedule:
- cron: '15 * * * *'

jobs:
    update-weather:
        permissions: write-all
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v3
            - name: Generate README
              uses: huantt/weather-forecast@v1.0.5
              with:
                city: HaNoi
                days: 7
                weather-api-key: ${{ secrets.WEATHER_API_KEY }}
                template-file: 'README.md.template'
                out-file: 'README.md'
            - name: Commit
              run: |
                if git diff --exit-code; then
                  echo "No changes to commit."
                  exit 0
                else
                  git config user.name github-actions
                  git config user.email github-actions@github.com
                  git add .
                  git commit -m "update"
                  git push origin main
                fi
  • Update some variable in this file:
    • city: The city that you want to forecast weather
    • days: number of forecast days
    • template-file: Path to the above template file. Eg. template/README.md.template
    • out-file: your README.md file name
    • weather-api-key:
      • Register free API key in https://weatherapi.com
      • Setup secrets with name WEATHER_API_KEY in Your repo > settings > Secrets and variables > Actions > New repository secret

Step 5: Commit your change, then Github actions will run as your specificed cron to update Weather into your README.md file

Usage

View

Install

go install https://github.com/huantt/weather-forecast

Run

Usage:
weather-forecast update-weather [flags]

Flags:
--city string              City
--days int                 Days of forecast (default 7)
-h, --help                     help for update-weather
-o, --out-file string          Output file path
-f, --template-file string     Readme template file path
-k, --weather-api-key string   weatherapi.com API key

Sample

weather-forecast update-weather \
--days=7 \
--weather-api-key="$WEATHER_API_KEY" \
--template-file='template/README.md.template' \
--city=HaNoi \
--out-file='README.md'

Docker

docker build -t weather-forecast .
docker run --rm \
-v ./:/app/data \
weather-forecast \
--weather-api-key='XXXX' \
--city=HaNoi \
--out-file=data/README.md \
--template-file=data/README.md.template

About

This project uses GitLab Actions to collect the weather then update to README.md

Resources

Stars

Watchers

Forks

Packages

No packages published