Modern Python Projects Transcripts
Chapter: Let's build a CLI
Lecture: Possible improvements
0:00 This is where we end, adding new features to our tool.
0:03 But if you find it interesting and you want to actually use it,
0:06 there are many more improvements that you can add.
0:09 First of all, we can make this code asynchronous.
0:12 Otherwise, if there is a website that takes long to respond,
0:16 it will block all the other URL's.
0:18 So, when you want to ping multiple url's,
0:20 using an asynchronous code is a textbook example.
0:24 You can also send an email, when the website is down.
0:28 Python has a module called SMTP lib, that you can use to send emails.
0:33 You can provide credentials, for example,
0:35 for your Gmail account and then add a function that will send you an email when
0:39 one of the website is down.
0:42 You can also add an option to display and notification when the website goes down.
0:47 Right now, when we run uptimer in a daemon mode,
0:49 we still have to check the output in the terminal from time to time.
0:54 So, it would be cool to get a pop up notification on your computer.
0:58 This is not an easy task because every operating system uses a different tool to send
1:03 desktop notifications. So if you're looking for a challenge,
1:07 check how to display notifications on your operating system from Python and try to add it to
1:12 our uptimer application. You can also add the script to a Cron job and
1:17 have it run every minute or every five minutes.
1:20 Cron is like automatic tasks scheduled on linux,
1:24 so if you have never used it before,
1:25 you can check it out. But when you use it,
1:28 it will run your application in a regular interval so you don't have to actually run
1:32 it in a terminal all the time.
1:35 You can add a database or a configuration file to store the list of websites that
1:40 you want to monitor. That way,
1:42 you don't have to always provide full list of url's,
1:44 that you want to monitor.
1:46 When you restart your application, you could start the
1:49 URL's in the database and add some functions to add list and delete URL from
1:56 the database. You can use a fancy database like Postgres SQL or mySQL.
2:01 But Python comes with SQL module built in,
2:04 so you can just import SQLlite three and create a database in the current folder
2:10 and that that's enough to get you started.
2:12 And if you want something really advanced,
2:14 you can add different types of requests,
2:16 not just the head request. All those tools that I showed you at the beginning
2:20 So the uptime robot and pingdom they let you,
2:24 for example, specify a user name and password,
2:27 and then they will try to look in at your website.
2:30 That way, you can check not only if the front page of your website
2:35 is running, but for example,
2:36 if the users can log in,
2:37 so if the database is working fine,
2:41 this will require a lot of changes.
2:43 You need to add additional parameters to accept the user name and password.
2:47 Then need to set up some SSL configuration to send those password securely,
2:52 and you need to add support for post request to the main function.
2:56 But when you do this, you'll have a really powerful uptime monitoring tool.
3:01 In the next chapter, we will take the uptimer and publish it on pypi.