Python Jumpstart by Building 10 Apps Transcripts
Chapter: App 5: Real-time weather client
Lecture: Getting the location

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Well, let's get started writing the pieces we got to write to build our applications. So the first one is, we'll just have a
0:06 print or show header, I guess we'll call it "show Header" and we'll come down here and write it like "def show_header()", super easy.
0:15 And remember, all the headers they look like, we'll add a couple of sections, and we'll say, whether client or weather app or something like that,
0:23 we'll roughly try to center it and then maybe just a new line at the end. Let's get rid of that part. Now
0:29 if we run it, you can see our little headers coming out the bottom. Great. The next thing we need to do is get the actual location.
0:36 We'll call it "location_text". Remember, this is not the location data yet. This is like human friendly plain text,
0:44 right? Stuttgart, Germany or Portland, Oregon, U.S.A., something like that. So we're gonna just get that from the user. We can just do a simple input
0:52 here. So we can say "where do you want the weather report" and put a
0:56 little message, and then we'll put this space here so they're not typing directly on that text, and let's just print out "you selected",
1:04 Now we could go like this, "location text", but if that came back as none, for some reason that would crash. And we could also do ".format
1:13 (location_text)" and put that there. But now that we're using Python 3.9 we can actually use what's called f-strings.
1:19 We put an f here, notice the color of the curly braces change and we can just put the thing we wanna format like that.
1:26 So here's a little cleaner, simpler thing what we might do. Okay, let's just see that this works. Okay. Where do you want?
1:31 I'm thinking Boston, U.S., You selected Boston, or I'm thinking maybe Boston, Massachusetts, USA, you selected Boston,
1:44 Massachusetts USA. Alright, well our getting this information from the user works. Next thing to do is convert it over to plain text,
1:53 hand that over to the API and then convert the API response over to some kind of human readable thing like "the weather is whatever it happens to be".


Talk Python's Mastodon Michael Kennedy's Mastodon