DEV Community

Verica Spaskovska
Verica Spaskovska

Posted on • Edited on

5 1

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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay