Playing with Python packaging
Python
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tests
weather_forecast_emailer
.flake8
.gitignore
.gitlab-ci.yml
.travis.yml
MANIFEST.in
README.md
requirements.txt
setup.py

README.md

Build Status build status Coverage Status

Weather Forecast Emailer

This libray gets the current weather for a city from the Open Weather Map web API and sends it to a list of emails from a specific Google account.

It is not an exhaustive or complete client wrapper for the OWM service. If that's what you need, pyown offers that functionality. This is just my pet project to practice package creation in Python.

Usage

Please use responsibly and don't spam people :)

You need four things:

  • An Open Weather Map API key: The Open Weather Map API needs a valid API key to allow responses. Create an account at the Open Weather Map site and copy your API key.

  • A Gmail username: This is the username of the Gmail account from where the emails will be sent.

  • A specific app password: Google needs you to give it permission to send emails in your behalf. Enable 2FA in the previous account and follow the steps in "Sign in using App Passwords" to get an app password.

  • A list of emails and names: These can be provided in a file or as a dictionary.

List of emails and names as a dictionary

You can provide the list of emails and names as a dictionary:

from weather_forecast_emailer import Emailer, Forecast

emails   = {'email1@domain.com': 'Name 1', 'email2@domain.com': 'Name 2'}
forecast = Forecast('YOUR_OWM_API_KEY').get_weather_forecast('uk', 'London')
Emailer('YOUR_USERNAME', 'YOUR_PASSWORD').send_emails(emails, forecast)

Replace uk and London with your country code and city name!

List of emails and names in a file

You can also provide the list of emails and names in a file and use the EmailListReader to get them as a dictionary.

In the file, eparate the email from the name with a comma:

# Contents of 'emails.txt'
email1@domain.com, name1
email2@domain.com, name2

then you can do:

from weather_forecast_emailer import Emailer, EmailListReader, Forecast

emails   = EmailListReader(open('emails.txt', 'r')).as_dictionary(',')
forecast = Forecast('YOUR_OWM_API_KEY').get_weather_forecast('uk', 'London')
Emailer('YOUR_USERNAME', 'YOUR_PASSWORD').send_emails(emails, forecast)

The weather condition codes are explained here.

Development

Install

pip install .

Install dependencies

pip install -r requirements.txt

Run tests

python3 -m unittest discover

Publish

python3 setup.py register sdist upload