Modern Python Projects Transcripts
Chapter: Let's build a CLI
Lecture: Our CLI application
0:00 You are probably wondering now what kind of program we're going to build.
0:05 Is it going to be a yet another calculator?
0:08 No. We are done with writing calculators in Python.
0:12 Let's actually build something useful. I've decided that I'm going to show you how to
0:16 build a tool for uptime Monitoring. Uptime,
0:19 Monitoring means checking in regular intervals that a specific website is up and running.
0:25 You can use it, for example,
0:26 when you have a personal website on the Internet and you want to get a notification
0:30 when it goes down, so you know that you need to go and fix it
0:33 Some of the existing uptime monitoring tools are,
0:37 for example, pingdom or a free alternative called uptimerobot.
0:42 So if you have never seen an up time monitor,
0:44 you can go check them out to see how they work.
0:47 But basically what they do is that you have an interface where you provide which
0:51 URL you want to monitor, and this tool will check every few minutes or every
0:56 few seconds. If your website is still running and then you can get,
1:00 for example, an email, notification,
1:02 slack notification and stuff like that.
1:04 There are even applications that will send you a push.
1:06 Notification. Our uptime monitor will be simple.
1:11 In the first version, we wanted to accept a URL, sent a head request and returned
1:16 What status? Code was returned.
1:18 Head request is identical to the get request.
1:21 But when you perform the head request,
1:23 the server doesn't actually returned the body of the website.
1:27 It only returns the headers and the status code.
1:30 And since we only want to get the status code,
1:32 we don't need to get the full content of the page.
1:35 So using ahead request will make our checks a bit faster because less data will be
1:40 traveling through the network. And once we get that response,
1:44 we will display using some colors in the terminal.
1:47 Status called of 200 means everything is fine.
1:50 So it will be green. Three or four means a redirect.
1:53 So we will display it in yellow just to give you a hint that probably this
1:58 URL should be updated. But your website is still accessible and any status code
2:03 that starts with digit 4 or 5 like 404 or 543 means
2:08 an error. So we'll display them in the red.
2:12 Once we have that, we will extend our tool so that it can accept multiple
2:17 URL and keep pinging them in regular intervals.
2:21 That way, we can constantly monitor multiple URL,
2:25 just like a proper up time monitor would do.