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. Is it going to be a yet another calculator?
0:09 No. We are done with writing calculators in Python. Let's actually build something useful. I've decided that I'm going to show you how to
0:17 build a tool for uptime Monitoring. Uptime, Monitoring means checking in regular intervals that a specific website is up and running.
0:26 You can use it, for example, when you have a personal website on the Internet and you want to get a notification
0:31 when it goes down, so you know that you need to go and fix it Some of the existing uptime monitoring tools are,
0:38 for example, pingdom or a free alternative called uptimerobot. So if you have never seen an up time monitor,
0:45 you can go check them out to see how they work. But basically what they do is that you have an interface where you provide which
0:52 URL you want to monitor, and this tool will check every few minutes or every few seconds. If your website is still running and then you can get,
1:01 for example, an email, notification, slack notification and stuff like that. There are even applications that will send you a push.
1:07 Notification. Our uptime monitor will be simple. In the first version, we wanted to accept a URL, sent a head request and returned
1:17 What status? Code was returned. Head request is identical to the get request. But when you perform the head request,
1:24 the server doesn't actually returned the body of the website. It only returns the headers and the status code.
1:31 And since we only want to get the status code, we don't need to get the full content of the page.
1:36 So using ahead request will make our checks a bit faster because less data will be traveling through the network. And once we get that response,
1:45 we will display using some colors in the terminal. Status called of 200 means everything is fine. So it will be green. Three or four means a redirect.
1:54 So we will display it in yellow just to give you a hint that probably this
1:59 URL should be updated. But your website is still accessible and any status code that starts with digit 4 or 5 like 404 or 543 means
2:09 an error. So we'll display them in the red. Once we have that, we will extend our tool so that it can accept multiple
2:18 URL and keep pinging them in regular intervals. That way, we can constantly monitor multiple URL, just like a proper up time monitor would do.