IBM Bluemix Weather Company API with Python

Here is a simple example of calling the IBM Weather Company REST API using Python. The program asks for a US ZIP code and then displays some of the data. A perfect program for an intro to programming class. Also, on GitHub.


# Using the IBM Bluemix Weather Company API
# Bruce Elgort
# July 9, 2016
# Version 1.0
# IBM Weather Company Docs: https://console.ng.bluemix.net/docs/services/Weather/weather_rest_apis.html#rest_apis

import requests
import json

def get_weather(zip):
    username = 'your username'
    password = 'your password'

    watsonUrl = 'https://twcservice.mybluemix.net/api/weather/v1/location/' + zip + ':4:US' + '/observations.json?language=en-US'

    try:
        r = requests.get(watsonUrl,auth=(username,password))
        return r.text
    except:
        return False

def display_weather(results):
    print()
    print('Here is the weather for {0}'.format(results['observation']['obs_name']))
    print('{0:20} {1:<10}'.format('Current Temperature:',str(results['observation']['temp']) + '° and ' + results['observation']['wx_phrase']))
    print('{0:20} {1:<10}'.format('Feels Like: ',str(results['observation']['feels_like']) + '°'))
    print('{0:20} {1:<10}'.format('Low Temp: ',str(results['observation']['min_temp']) + '°'))
    print('{0:20} {1:<10}'.format('High Temp: ',str(results['observation']['max_temp']) + '°'))
    print('{0:20} {1:<10}'.format('Winds:',str(results['observation']['wspd']) + ' mph coming from the ' + results['observation']['wdir_cardinal']))

def get_weather():
    zip = input('Enter US ZIP code to get weather for:\n')
    results = get_weather(zip)
    if results != False:
        results = json.loads(str(results))
        display_weather(results)
    else:
        print('Something went wrong😦')

if __name__ == '__main__':
    get_weather()

Learn to Program with Python

Sometimes You Go Back To Bed

In this week’s episode of Getting Work To Work, Chris Martin talks about owning your schedule and the importance of taking care of your physical and mental health. As creative professionals, it can be easy to push your needs aside for the sake of the work, but sometimes you go back to bed to hit the reset switch.

Listen now >

And I’m Back

IMG_0221.png

I’m delighted to be part of Clark College for another year. This marks my fourth year at the college teaching web development. Here’s a list of all the courses that I have taught:

  • Intro to Programming and Problem Solving with Python (CTEC 121)
  • HTML Fundamentals (CTEC 122)
  • JavaScript (CTEC 126)
  • Business Web Practices (CTEC 165)
  • PHP with SQL 1 (CTEC 127)
  • PHP with SQL 2 (CTEC 227)
  • API & Advanced Integration (CTEC 228)
  • WordPress Development (CTEC 260)

Why I didn’t Look at Your Resume

If you’re looking for a new gig or career, I wanted to share this list of hiring red flags publicly. These things to watch out for will vary by industry and company, but if you’re looking for a position at a startup, an agency, or something in the online industry, this list may help you avoid ending up in the immediate ‘no’ pile.

Read Mikael Cho’s entire article >

Generalists vs. Specialists

In this week’s episode of the Getting Work To Work podcast, Chris Martin talks about whether an artist should be a generalist or a specialist. As a creative generalist with interests in multiple subjects including filmmaking, web design and development, photography, teaching and more, Chris struggles with the advice of picking one pursuit and doing only that.

More >

I Do Not Agree

Going to shit

2015 is when web development went to shit. Web development used to be nice. You could fire up a text editor and start creating JS and CSS files. You can absolutely still do this. That has not changed. So yes, everything I’m about to say can be invalidated by saying that.

Read “The Sad State of Web Development” >

I’m a 2016-2017 IBM Champion for Cloud

Late on Friday, I received an email from IBM letting me know that I was named an IBM Champion for Cloud. I’m honored to be part of this inaugural group of individuals. A huge thank you to those people who nominated and encouraged me to start using Bluemix.

What is Professional?

In this week’s episode of Getting Work To Work, Chris Martin responds to listener feedback, discusses whether professional is a label or an attitude, share wisdom from books by Steven Pressfield and Austin Kleon, and encourages creative professionals to create work daily regardless of whether it is “professional” or not.

Listen now >

The Joy Effect

Follow

Get every new post delivered to your Inbox.

Join 2,034 other followers