Never be late again with the help of this neat coding project!
Sometimes you need someone, or something, to remind you of a task or an event, like doing the laundry or going to a meeting. The ScheduleBot was created for this very purpose by saying the reminder to you at the time you want. After answering some questions to the bot about what your event is, when it takes place, and when you should be reminded, the bot will save your request and remind you.
ScheduleBot can run on any computer. However, I used a Raspberry Pi. That way, I can find a room that I spend most of my time in and insert the Raspberry Pi there. If you were to run the code on a laptop, you would have to power it off eventually, but the ScheduleBot program can (and must) run continuously. Running the code on a PC would mean that you would have to stay in the room with the PC to hear your reminders, but that might not be the room where you would like to hear your reminders. However, you can pick the location for the Raspberry Pi that would be most convenient for you.
- Raspberry Pi
- 2 DC Adapters
- Python programming language
Set up the Raspberry Pi. The Raspberry Pi  is a small computer that is powered by one single circuit board. The Raspberry Pi may be much smaller than the average computer, but it can still do what a regular computer can. However, the Raspberry Pi may take longer to do what a computer can do.
- Figures 1-4 explain which plugs are which, why they are needed for the Raspberry Pi, and how to insert them. Follow the pictures and plug them accordingly.
- Turn on the Raspberry Pi. It will turn on automatically when the two power plugs are in, or hit the power button on the Raspberry Pi.
- Connect to the internet for initial software installation.
Set up the Python packages. Open a terminal window and install the following Python libraries (Python 2 and 3 will already be installed on your Raspberry Pi but you need to use Python 3):
- keyboard : enables you to access keypresses from the keyboard while code is executing.
- pyttsx3 (Python Text-to-Speech X-Platform): a library that converts text given to it into speech in order for you to program your ScheduleBot to speak your event reminders.
Write the code. Open a text editor on Raspberry Pi to begin writing code. Name code in a way you can remember (ex: scheduleBot.py) but make sure it ends in .py!
1. Import the datetime, keyboard, pyttsx3, and time libraries. In addition to the previously installed libraries, datetime (which is already installed into Python by default) is used to access the current date and time during execution. We have three times of interest associated with our program flow. Current time describes the precise current time, the event time is when the event takes place, and the reminder time is when to execute the reminder. When you see your reminder, it will show the event time in military time. In the program, for comparisons, the times will be compared by the event hour (before the colon) and the event minute (after the colon). (See Figure 5)
2. Write a function called convert_date_string_format with the parameter date_with_dashes. This function will take the string date_with_dashes and will change it from YYYY-MM-DD to MM/DD/YYYY. The function should return the converted date. (See Figure 6)
3. Write the function time1_less_than_eq_time2 with the purpose of checking if one time is before another so the program can compare times. For example, if one time is before or after another, the computer can know if an event is in the past or if the reminder time is after the event time. (See Figure 7)
4. Write a function sort_events to sort the events in chronological order from the event that will occur soonest to the event that will occur latest. The first two events in the list are checked to see if they are in the correct chronological order. If they aren’t, the code swaps them and checks the next two elements. If they are, the code doesn’t switch them and keeps checking. We repeat this procedure n times, where n is the length of the list, to ensure that all elements are sorted to their true position. This is called BubbleSort. (See Figure 8)
5. Make a Class  called Event. A Class is a data type that describes the data it has and what a programmer can do with it. (See Figure 9). Make sure this Class has:
- event_name (the name of the event)
- event_time (the time of the event)
- event_date (the date of the event)
- event_reminder_date (the date of the reminder for the event)
- event_reminder_time (the time of the reminder for the event)
6. Write the function checkForReminders. This function will check for reminders to make sure if there are any reminders needed and when to execute them. You should use the function time1_less_eq_time2 because it will let you compare the current time and the reminder time so the computer can know whether or not to give out a reminder. (See Figures 10 and 11)
7. In the main function (if __name__ == ‘__main__’), there’s a few things you can do. First, you can make an “if” statement that will make a new event when you press the letter “n” on your keyboard. Second, you can make an “if” statement in your code that will print upcoming events in the ScheduleBot (in chronological order) when you press the letter “p”. Use the function sort_events to put the events in chronological order, and make a for loop to print each event in the list_of_events, one event at a time. (See Figure 12)
Add functions to validate the data. Some functions are to make sure that the information is given to it in the way expected and meets all requirements. These functions are important because they help make the program run correctly, give you accurate reminders, and store your event data correctly.
1. Write a function called eventIsInThePast. The function should return True if the event is in the past, and False if not. The event given by the user must be in the future, so if the user gives the program an event that is in the past, the program needs to know so it can let the user know what they did wrong. If it didn’t, there would be no way for the program to know, and it would create an invalid event. (See Figure 13)
2. Write a function called validMilitaryTime. This function is going to make sure that your event’s time is valid. Make sure the function returns True if the military time is valid, and False if not. (See Figure 14)
3. The next function you need to code is to make sure the date is valid. Name the function validDate. The function should return True if the date is valid, and False otherwise. (See Figure 15)
4. This function is going to check if the event is valid. Name the function checkValidEvent. The criteria I use for the events are:
- Name is less than or equal to 300 characters
- Is in the future
- Event is less than two years into the future
- The event’s military time is valid
- The reminder’s date is no more than a month before the event
- The reminder’s time is valid military time
If all criteria apply to the event, the function should return True, and if the event does not follow the criteria, return False and have your function print what is wrong with the event. (See Figure 16)
Run the code. Open the terminal on the Raspberry Pi and run your program using the command “sudo python scheduleBot.py”. Sudo  is used to let someone use code as the super user. This is the super user because this user can perform actions that other users can’t. This will let you access scheduleBot.py (because you will be accessing the code as another user). Sudo also allows you to use files and make actions that wouldn’t be allowed if as another user. This is important so that the program can use the computer speakers to tell us reminders, and the keyboard to type in events and use the n key to make a new event. If you wish to test the code, we have written tests which you can check out on GitHub, linked at the bottom of the article.
Customize your ScheduleBot code. Some parts of the code here are just customizations for this version of the ScheduleBot. For example, I wanted to have a limit for the reminder time for it to be no more than a month before an event, so I added that customization. Customizations are not required. You can make your own customizations if you wish.
1. Write a function called reminder_date_within_a_month_of_event. This will make sure the reminder date is within a month before the event it’s reminding you of. This is just one of the custom restrictions I put in my code. It is completely optional, and you can skip this step if you would like. (See Figure 17)
2. Write a function titled two_years_future. This function is going to check to see if the event is farther than two years into the future, for the events can’t go further than that time. The function should return “True” if the function’s event is within two years of the future, and “False” otherwise. This is another customization in my code and is not required. You can skip this step if you want to. (See Figure 18)
The ScheduleBot will help you remember what you need to do. There were definitely challenges to making the bot, from converting it across the computers to simple debugging errors. During the making of this robot, the popular Python code has done many spectacular things that you may not expect, such as being able to say words and being able to put your own input in, without writing code. Unlike other calendars, the ScheduleBot actually will say the reminder you requested for. The bot shows the amazing things that Python can do, and that you can make so many amazing things with this coding language. Code for ScheduleBot
Hook and simulate keyboard events on Windows and Linux
Linux 101: Introduction to sudo
Teach, Learn, and Make with Raspberry Pi
Codecademy Introduction to Classes
What Happened to Schedule Bot?
Also In The August 2022 Issue
This method of detecting marine waste is truly out of this world!
Looking for free computing resources for your classroom? Check out Computing at School!
Never be late again with the help of this neat coding project!
From bulletproof vests to stronger tires, Kevlar is a really versatile material!
Time to learn how humans have kept track of time over the centuries
Check out how programmers are competing to make an even simpler Wordle!
Your dreams of having a robotic friend may be closer than you think!
Check out some of the cool ways virtual reality is being used in medicine!
A sandy problem requires a sandy solution!
Learn how you can use retro game design to help kids embrace their creativity!
Make a kitchen timer with this quick coding lab!
Perlin noise is as random as it gets!
Leave your mark on the world wide web with your own website!
cURL up on the couch and check out this cool open-source tool!
You know leap forward and fall back, now add a little kick with a leap Second
Check out some of the cool tech being invented for pets!
Discover the true origins of the great poop emoji!
Pokemon in Minecraft? Tell me more!
Collection of the Learnmore links from all of the August 2022 stories, in one place.
Interesting stories about computer science, software programming, and technology from August 2022.