Python Jumpstart by Building 10 Apps Transcripts
Chapter: App 5: Real-time weather client
Lecture: Weather API overview

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's have a quick look at this real time weather API that we're going to be using. So, there's a lot of weather API endpoints out on the Internet.
0:09 In fact, one that I think is really cool is "openweathermap.org". So if you're going to really try to create a live weather application,
0:15 go use theirs. This one is just for educational purposes, has limited data and so on,
0:20 but it will give us the answers generally that we're looking for here. So this is a HTTP RESTful
0:27 API. And what that means is we just make HTTP requests, like standard web browsers do, and what we get back typically, not always,
0:34 but typically is some kind of formatted data called JSON. So, what we can do is we can go over here and say "weather.talk Python.fm/api/weather"
0:46 and it requires that we pass some things. So if we don't pass a city, it says "missing field: City" so we could put "Boston", Sorry,
0:54 we could put "city = Boston" like this, there we go. And apparently, the weather is mist. Some kind of mist rain, I don't know.
1:02 It should be category: rain, description: mist. Who knows? Here you can see,
1:05 we're getting the weather. It's right now 13 degrees Celsius because down here somewhere we
1:12 have our units are metric. If we wanted this to be in more US style we could say "units = imperial". Now all of a sudden
1:20 it's 55°F instead of whatever it was Celsius. Okay, So what we do is we make a regular request and we get data that looks like this back from it.
1:30 So this is called JSON, and we'll see how to play with it in Python really soon. But it's a nice,
1:35 simple format That's very, very natural for us to work with over API. And if we come back here, you can see that we have a city,
1:42 right? This should have a question mark. actually. It says that we have a city equals whatever we want, but we can optionally pass a state,
1:50 if you want to disambiguate say Portland, Maine, from Portland, Oregon. We can pass a country we wanna disambiguate Portland, Australia, from Portland,
1:58 USA. If you don't specify a country, it defaults to the US, Just that way. I could type in short city names and
2:03 it's still gonna work. Then also you saw we can pass in units as metric, imperial or standard, and it defaults to metric.
2:10 So this is the weather API that we're going to be working with.


Talk Python's Mastodon Michael Kennedy's Mastodon