Daily Weather Email – PYTHON – CRON – API

I was interested in the weatherunderground API for getting real time weather updates via the API and python.
WeatherUnderGroundApiLink:
http://www.wunderground.com/weather/api/
I was particularly interested in learning how to use the JSON python module. So I thought I would give you people a quick and dirty write up of how I get a daily weather update with endless categories via email on linux using python.

Ok so here we go, don’t get all excited and post this on hacker news and crash my t1.micro at AWS.

Let’s have a lookie at the python script where the magic takes place. O Yeah you will need to get an API KEY from WeatherUnderground for this. Look here:
http://www.wunderground.com/weather/api/d/login.html

The API will look like this once you obtain your copy:

Here is the link for requests:
http://docs.python-requests.org/en/master/
Ok let me break down the PY code:

It’s probably important to see what we get back from the API in JSON so the below code makes sense. Here we go, this is just pretty printing the JSON using pythons PPRINT module, Showing this snippet first to help understand the code.

SCRIPT:

OUTPUT:

Ok let’s parse this JSON and send a freaking daily email with the fields we want, O Yeah.

Here is the script commenting on what we are doing.

Here is what comes out of this python script when we call the JSON variables we are attracted to:

Ok let’s wrap this biatch into a shell script and have it call mail on linux so I can get a daily updates on the weather for Milford CT whenever I call the cron.

Here is the directory structure I setup for the scripts:

Here is the bash script that I wrote to bring it all together, it calls the python script and writes a log and mails it.

Here is the cron:

Here is my morning email message:

View post on imgur.com

Hope you had fun, I did. O and let me know how bad this post is and how you can do it better.
Love you