#100DaysOfCode in Python Transcripts
Chapter: Days 43-45: Consuming HTTP services
Lecture: Demo: Building the program structure

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So it's time to get started writing our search app
0:02 that's going to talk to the movie search API.
0:05 Now over here in our repository,
0:06 I've got Day 10 to 12 selected
0:09 and I've opened up the terminal here.
0:12 We want to open this in PyCharm.
0:14 You don't have to use PyCharm,
0:16 but I'm going to open in in PyCharm.
0:17 I'm going to go through a couple of steps.
0:19 Whenever you depend upon external packages,
0:21 it's a good idea to have a virtual environment.
0:24 In order to create one of those over here,
0:25 let's call this app, let's make a folder really quick.
0:30 So call this Movie Search.
0:32 And go in here.
0:33 Then, I'm going to create a virtual environment here.
0:37 If we call it .env or venv,
0:40 then PyCharm will automatically detect it and use it,
0:42 so might as well call it that.
0:45 Now open this in PyCharm,
0:46 can't seen anything because dot creates hidden files on Mac
0:49 and Linux, but we're going to open this
0:52 on Mac and Linux, you have to say file, open, directory
0:56 and Mac, you can just drop it here.
0:59 Let's go ahead and tell PyCharm about about git,
1:02 so everything I create is going to be put
1:04 into the git repository for you.
1:06 And that'll be a little easier here,
1:08 go ahead and also tell it to ignore this directory.
1:12 Maybe someday it'll do that on it's own.
1:13 Now I want to create two files,
1:15 I don't like to cram everything into one Python file.
1:19 When I'm creating an application
1:20 I want to partition it into pieces so let's go over here
1:23 and create two things.
1:24 We're going to create a program
1:26 and we're going to create an API.
1:31 And go ahead and tell PyCharm it can add stuff to git.
1:34 Okay so what we're going to do
1:35 is we're going to write the code to access the service
1:38 in the API file and we're going to work with it
1:41 from the user interaction perspective
1:43 and orchestrate it from over here.
1:45 So let's define a quick method over here, main.
1:48 And we'll just have pass.
1:50 Now we want to follow the convention for running this program
1:54 if and only if it's the target of execution.
1:57 And in PyCharm, the way that,
1:58 or, in Python, the way that you do that
2:00 is you use this if dunder name equals dunder main,
2:03 then that means it's supposed to run
2:05 and I'll just call this method here.
2:09 This is a little bit set up and ready to go.
2:11 We're going to use something over in the API
2:14 so we're going to create a method here
2:16 that's going to take a string
2:18 and it's going to return some search results.
2:19 So create.
2:21 And say find movie by title, let's say,
2:25 because that's what we're actually searching for here.
2:27 And the keyword, and it's going to do some stuff
2:31 and return some movies, that's going to be great.
2:33 How do we do that?
2:34 Well first we have to work with requests.
2:36 So we'll come over here and say import requests.
2:38 Now let me go ahead and run this,
2:41 it's not going to work out so well,
2:43 we're going to right click and create a run configuration
2:45 in PyCharm, or you just type Python 3, you know,
2:48 program.py.
2:51 That didn't actually import it so nothing actually happened.
2:53 But let's do, if we come over here and say import api
2:56 as we're going to need to, now we try that again, boom,
3:00 there is no requests. So of course we have to install requests.
3:03 Now if you look in our terminal,
3:05 notice we have the virtual environment activated here,
3:08 so we could say, see what's in there.
3:11 And there's nothing really in there.
3:14 So one of the conventions people like to follow
3:16 is when they have dependencies
3:19 they'll have a file called requirements.txt.
3:23 And in there, they'll put library names like requests.
3:27 requests, like this.
3:29 And notice, PyCharm already knows,
3:31 hey, you need to say pip install requests,
3:33 or you can just click this and that'll do it for you.
3:37 If you wait for a second down here
3:38 and then we do the pip list again,
3:39 there should be more stuff including requests,
3:42 our program should now run.
3:44 Ta-dah, okay.
3:45 So we have just the basic structure of this thing
3:47 hanging together, right?
3:49 We've installed requests, we've created the program,
3:52 and the api separation, we've got our requirements,
3:54 and it's all kind of hanging together.
3:57 Next up, we actually have to write
3:59 our method here, about how we find movies.