├── README.md ├── weather.sh └── .github └── workflows └── action.yml /README.md: -------------------------------------------------------------------------------- 1 | An example of GitHub Actions: sending daily weather report with email. 2 | 3 | Visit [my blog](http://www.ruanyifeng.com/blog/2019/12/github_actions.html) (in Chinese) for details. 4 | 5 | ## References 6 | 7 | - [signalnerve/github-actions-weather-bot](https://github.com/signalnerve/github-actions-weather-bot) 8 | - [chubin/wttr.in](https://github.com/chubin/wttr.in) 9 | -------------------------------------------------------------------------------- /weather.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -eux 4 | 5 | CITY=Shanghai 6 | LANGUAGE="zh-CN" 7 | UNIT=m 8 | UA="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" 9 | 10 | curl \ 11 | -H "Accept-Language: $LANGUAGE" \ 12 | -H "User-Agent: $UA" \ 13 | -o result.html \ 14 | https://wttr.in/$CITY?format=4\&$UNIT 15 | -------------------------------------------------------------------------------- /.github/workflows/action.yml: -------------------------------------------------------------------------------- 1 | name: 'GitHub Actions Weather Bot' 2 | 3 | on: 4 | push: 5 | workflow_dispatch: 6 | schedule: 7 | - cron: '0 21 * * *' 8 | 9 | jobs: 10 | bot: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: 'Checkout codes' 14 | uses: actions/checkout@v1 15 | - name: 'Get Weather' 16 | run: bash ./weather.sh 17 | - name: 'Get Date' 18 | run: echo "REPORT_DATE=$(TZ=':Asia/Shanghai' date '+%Y-%m-%d %T')" >> $GITHUB_ENV 19 | - name: 'Send mail' 20 | uses: dawidd6/action-send-mail@master 21 | with: 22 | server_address: smtp.163.com 23 | server_port: 465 24 | username: ${{ secrets.MAIL_USERNAME }} 25 | password: ${{ secrets.MAIL_PASSWORD }} 26 | subject: Shanghai Weather Report (${{env.REPORT_DATE}}) 27 | html_body: file://result.html 28 | to: yifeng.ruan@gmail.com 29 | from: GitHub Actions 30 | --------------------------------------------------------------------------------