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.
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.
The os and dotenv modules are used to access the environment variables used in this project.
Requests is used to query the OpenWeatherMap API used in weatherdata.py.
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 is used to send an email to a recipient of the weather data that is pulled and formatted.
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.
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.
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.
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.
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.

