Skip to content

Day 98 of the 100 Days of Code course. The goal for the project was to create a program that can automate something. For my project, I chose to build on the custom API web app project.

Notifications You must be signed in to change notification settings

briansalazar-tech/100DaysofCode-Python-Automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

100 Days of Code Day 98: Email Ski Resort Weather Data (Custom Python Automation)

This project is a riff on Day 96’s API Based Flask Website. Instead of creating a website that utilizes an API, this program sends an email using the data pulled from the OpenWeatherMap API.

Technologies Used

OpenWeatherMap 5-Day 3-Hour API

OpenWeatherMap’s 5-day 3-hour API is used for this project. To use the API, an API key must first be obtained by signing up. The 5-day 3-hour API was used because it was free to use without providing payment information.

Modules Used

Os & Dotenv

The os and dotenv modules are used to access the environment variables used in this project.

Requests

Requests is used to query the OpenWeatherMap API used in weatherdata.py.

Datetime

Datetime is used to format datetime values retrieved from OpenWeatherMap in weatherdata.py. Additionally, the library is used to get the current date when sending a daily email.

Smtplib

Smtplib is used to send an email to a recipient of the weather data that is pulled and formatted.

Project Files

Main.py

Main.py is responsible for formatting the data that is passed through from weatherdata.py and sending an email to a recipient containing the formatted data.

Weatherdata.py

This file is responsible for querying OpenWeatherMap for weather data of each of the resorts stored in the file's constants. Once the desired information is pulled, the data if formatted to be output using the generate_tables function. Generate_tables output is passed through to main.py to be sent in an email.

Resort_execute.ps1

Using Windows Task scheduler, this file is used to execute the script file daily by calling on main.py, which then calls weatherdata.py to gather the weather data used.

Project Walkthrough

Compiling the weather data (weatherdata.py)

The project gathers weather data for the necessary coordinates saved in constants on weatherdata.py. Those coordinates are passed through a function called pull_weather_data. Using this function, OpenWeather’s 5-day 3-hour forecast is queried using the coordinates, and pertinent information is saved to a dictionary called resort_template. This process is repeated for each resort, and the dictionary entry is appended to a variable called resorts_list, which is returned as an output.

In this project, the pull_weather_data function gets called within another function called generate_tables. After pull_weather_data finishes executing, the generate_tables function proceeds to format the data, including the datetime values. Afterwards, the data is transformed into list entries. This transformation is necessary as each list entry will be used in the email's body as a new line. This process is repeated for each resort that is returned from pull_weather_data. Each resort is appended to a variable called resort data, which is then returned as an output.

Composing an email and sending the email (main.py)

Back in main.py, generate tables is imported from the weatherdata file. The function is executed, and the output of the function is used to compose the body of the email. Using loops, the program loops through each resort entry and each weather data timestamp to compose the email's body. Each list entry is appended to the email as a new line, as depicted in the screenshot.

The last step in this process is to send an email. This is accomplished using the smtplib library.

Project Flowchart

Weather data email project flow chart

Project Screenshots

Email screenshot

About

Day 98 of the 100 Days of Code course. The goal for the project was to create a program that can automate something. For my project, I chose to build on the custom API web app project.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published