0% found this document useful (0 votes)
7 views

workshop 04 - Calling an API from Python

Uploaded by

ms13061312
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

workshop 04 - Calling an API from Python

Uploaded by

ms13061312
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

4CS017 – Internet Software Architecture tutorial

Python and APIs (important: for fun - not required for the
assessment)

What will you learn today?

Use a different programming language to access the same Weather API.

Part 1 – Calling the Weather API from Python


One of the benefits of our Service-Oriented Architecture is that several clients (phones, smart TVs,
computers, consoles etc.) using a variety of operating systems and programming languages can
access the same API… let’s demonstrate the point by calling the same Weather API as before, but
with a language you learned in semester 1: Python!

1. Type and run the code below (in either Idle or Pyzo):

Notice how the code is similar to JavaScript (get data, convert to JSON object, display)

Part 2 – Updating our Deployment Diagram


Update your UML Deployment Diagram by adding your Python artefact running in the Python
runtime environment (on the same hardware node, since it still runs on your PC).

Part 3 – Going further


“I have finished all the work above, what shall I do next?”

Improvement to your Python script:

1. Ask the user to enter a city name (using the input function)
2. Deal with exceptions (e.g. the user misspells the name of the city)
3. Run the code on your Raspberry Pi and turn on red/ember/green LEDs depending on the
severity of the weather, or coldness of temperature 😊 Add Raspberry Pi to your diagram.

You might also like