#100DaysOfWeb in Python Transcripts
Chapter: Days 21-24: Async Flask APIs with Quart
Lecture: Your turn: Day 2 - Async program

Login or purchase this course to watch this video and the rest of the course contents.
0:00 This wouldn't be 100 Days of Code course
0:02 if you didn't write some code.
0:03 So now, it's your turn.
0:06 Let's go over to the Quart section of our GitHub repo
0:08 and notice that there's a code that we wrote
0:11 and then there's a your_turn section
0:13 so that's where it gets interesting for you.
0:16 We have something for you to do on day two
0:18 and something for you to do on day four.
0:21 So let's talk through, really quickly
0:22 what we're going to do in the first section here.
0:25 Well, the first part is to watch the videos
0:28 and I'm guessing if you got this far
0:29 well, then, you've watched the videos, awesome!
0:31 So you're kind of done with day one
0:33 play around with some of these ideas
0:34 and just make sure you kind of understand
0:36 what's going on in the videos.
0:38 So on day two what you're going to do
0:39 is play with a pre-existing app that we've already built.
0:42 This one is called web_crawl, and it's just
0:44 a terminal-based app, and what it does
0:45 is it goes and downloads like, 20 webpages
0:48 off of talkpython.fm, and just prints out the title.
0:51 It's kind of not really valuable, but it's a
0:54 really good chance to leverage async programming.
0:57 So what you're going to do is you're going to create
0:58 a virtual environment and activate it
1:00 and there's a set of requirements to make this work
1:02 so you got to make sure that you install
1:03 those after you activate the environment.
1:06 Then when you run it, you'll see that it does a few things
1:09 it says get me the html, and then from the html
1:11 it gets the title and then it prints out the title
1:13 for episode 150, then it does it for 151
1:17 then it does it for 152.
1:19 Well, what do you think your app is doing most of the time?
1:22 It's waiting for talkpython.fm
1:24 to stream that html back to you.
1:28 Now that happens pretty quick on the site
1:29 but there's things like latency on the internet
1:31 and all sorts of stuff, so you could really
1:33 ramp up the speed in which this happens
1:35 if you leveraged async, so that's your job.
1:38 What you're going to do is you're going to go to the
1:40 get_html method, you'll see that in the code
1:43 that's provided for you, you're going to convert
1:45 that method to be async, and we're going to use
1:48 this thing called aiohttp Client.
1:51 So this lets you do, as a client, kind of like
1:54 requests the requests library that lets you make
1:57 http requests, but this one supports async
1:59 so you can do async type of stuff like
2:02 get a URL or read the text stream, things like that.
2:07 So in this part, this is day two, your job
2:09 is to go through and convert this thing
2:12 we're calling web_crawl, up here
2:15 convert that from a synchronous program
2:17 to an asynchronous program.
2:19 There's a final little trick here at the end
2:21 that you actually have to leverage to make things
2:23 truly go faster and truly happen in parallel
2:26 and I'll just leave that for you to discover
2:29 as you go through this whole project.
2:31 All right, hope you have fun on this day
2:33 there's a lot of sort of step-by-step instructions
2:35 but it's not meant to be hand-holding
2:37 you're supposed to explore these ideas
2:39 so hopefully that balance is there.
2:41 And most importantly, have a great time.