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
0:02 we got to write to build our applications.
0:03 So the first one is, we'll just have a
0:05 print or show header, I guess we'll call it "show Header" and we'll come down
0:10 here and write it like "def show_header()", super easy.
0:14 And remember, all the headers they look like, we'll add a couple of sections, and we'll
0:18 say, whether client or weather app or something like that,
0:22 we'll roughly try to center it and then maybe just a new line at the
0:25 end. Let's get rid of that part. Now
0:28 if we run it, you can see our little headers coming out the bottom.
0:31 Great. The next thing we need to do is get the actual location.
0:35 We'll call it "location_text".
0:37 Remember, this is not the location data yet.
0:39 This is like human friendly plain text,
0:43 right? Stuttgart, Germany or Portland,
0:45 Oregon, U.S.A., something like that.
0:47 So we're gonna just get that from the user. We can just do a simple input
0:51 here. So we can say "where do you want the weather report" and put a
0:55 little message, and then we'll put this space here so they're not typing directly on that
0:59 text, and let's just print out "you selected",
1:03 Now we could go like this, "location text",
1:06 but if that came back as none,
1:07 for some reason that would crash.
1:09 And we could also do ".format
1:12 (location_text)" and put that there.
1:14 But now that we're using Python 3.9 we can actually use what's called f-strings.
1:18 We put an f here, notice the color of the curly braces change and we
1:21 can just put the thing we wanna format like that.
1:25 So here's a little cleaner, simpler thing what we might do. Okay,
1:28 let's just see that this works.
1:29 Okay. Where do you want?
1:30 I'm thinking Boston, U.S., You selected Boston,
1:36 or I'm thinking maybe Boston, Massachusetts, USA, you selected Boston,
1:43 Massachusetts USA. Alright, well our getting this information from the user works.
1:49 Next thing to do is convert it over to plain text,
1:52 hand that over to the API and then convert the API response
1:55 over to some kind of human readable thing like "the weather is whatever it happens to be".