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


Talk Python's Mastodon Michael Kennedy's Mastodon