DEV Community

Verica Spaskovska
Verica Spaskovska

Posted on • Edited on

Daily Forecast email using Github Actions

Mailbox

My Workflow

This workflow sends a daily weather email report using Gmail, Cron and AccuWeather API for a particular city.

  • create node.js script
  • import nodemailer to send email with Gmail SMTP server npm install nodemailer
  • set up the Google App password for sending authenticated mail
  • use dotenv to set up environment variables to secure data npm install dotenv
  • create .gitignore file for .env and node_modules files
  • automate the daily report email using Github Actions

yaml file

name: Daily Forecast

on:
   schedule:
   - cron: "0 14 * * *"
   workflow_dispatch:

env:
    MAIL_USER_EMAIL: ${{secrets.MAIL_USER_EMAIL}}     
    MAIL_USER_PASSWORD: ${{secrets.MAIL_USER_PASSWORD}}                                                              
    MAIL_FROM: ${{secrets.MAIL_FROM}}
    MAIL_TO: ${{secrets.MAIL_TO}}
    ACCUWEATHER_API_KEY: ${{secrets.ACCUWEATHER_API_KEY}}
jobs:
  report:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}

    - run: npm ci
    - run: node src/main.js
Enter fullscreen mode Exit fullscreen mode
  • use Cron to schedule when the node script is running
  • add the local forecast with AccuWeather API
  • create an App on AccuWeather system
  • install nodefetch to use the browser fetch API inside the node script
  • add the query parameters from the Location API and Forecast API to the project
  • merge your changes to the Github repository
  • store the environment variables MAIL_FROM, MAIL_TO, MAIL_USER_EMAIL, MAIL_USER_PASSWORD and the API key ACCUWEATHER_API_KEY as Github action secrets and run the workflow

Submission Category:

Wacky Wildcards

Link to Code

daily-forecast

๐ŸŒฆ๐ŸŒก Daily weather forecast report using Gmail, Cron and AccuWeather API ๐ŸŒž๐ŸŒง

image

Additional Resources / Info

Adding the local forecast with the AccuWeather API
https://developer.accuweather.com/
Setting up a Google App Password to use for sending authenticated mail with Gmail
https://support.google.com/accounts/answer/185833?hl=en
Gmail SMTP settings
https://support.google.com/mail/answer/7126229?hl=en#zippy=%2Cstep-change-smtp-other-settings-in-your-email-client

Top comments (0)