paint-brush
How to Build a Simple Python Reminder Appby@evgeniy-lebedev
41,449 reads
41,449 reads

How to Build a Simple Python Reminder App

by Evgeniy LebedevNovember 18th, 2019
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

The program will be very simple: Ask user what it wants to be reminded about Ask when (in what amount of time, in minutes) Calculate timeout (minutes multiply by seconds) Wait for the specified time Remind of what I requested in step 1. For example, in steps 1 and 2, I can communicate through different channels: keyboard, voice, or messaging apps. But for now, let’s stick with the simple stuff: the implementation of each step can make this app very useful.

Company Mentioned

Mention Thumbnail
featured image - How to Build a Simple Python Reminder App
Evgeniy Lebedev HackerNoon profile picture

I assume you know nothing about programming and want to try and make something with the world’s programming sweetheart — Python. 

The algorithm

The program will be very simple:

  1. Ask user what it wants to be reminded about
  2. Ask when (in what amount of time, in minutes)
  3. Calculate timeout (minutes multiply by seconds)
  4. Wait for the specified time
  5. Remind of what I requested in step 1

Although the algorithm is simple, the implementation of each step can make this app very useful. For example, in steps 1 and 2, I can communicate through different channels: keyboard, voice, or messaging apps. 

I can also alter the algorithm itself, for example, to make it death-proof: if your computer shuts down during step 4, it needs to know what it has to remind you about. But for now, let’s stick with the simple stuff.

The implementation. Step 0: Setting things up

I make a simple thing: take every step of our algorithm and show how it can be implemented in Python. First, though, I need to get things ready. Here is a Python command that I need to use: 

import time

Import tells Python to load a module with the tools that I need for the task. Time is the name of the module. From that module, I’ll need a method called ‘sleep’ that I’ll use to pause the program for a set amount of time.

Step 1: Asking for reminder

I need to ask the user and get a response. In a perfect world, I’d want a code like this:

reminder = user.ask("What shall I remind you about?")

And somewhere in the program, I’ll need to define what user and ask mean. It may be a message sent over Telegram, or it could be a voice prompt, or maybe have a robot approach user with a happy face and display the message on the screen. Implementation could be different, and I’d define it in a separate place in our program.

But I want a simple implementation, so I’ll go with some built-in commands:

print("What shall I remind you about?")

Print sends out a text message into Python’s default output (which in our case is command line).

text = str(input())

This means:
Take whatever the user has written, think of it as text, and put it into memory under the name “text”. Input() reads whatever the user inputs. Str() turns whatever had been input into text. Equals means “put one thing into memory with such name.”

Step 2: Asking for time

I need time in minutes. Here goes:

print("In how many minutes?")
local_time = float(input())

The second line means: Take whatever user typed, think of it as a number, put it in memory under the name “local_time”.

Step 3. Calculate timeout

I have a number of minutes that our app needs to wait before reminding us. But Python’s time.sleep() method requires seconds, not minutes. So I need to convert minutes to seconds:

local_time = local_time * 60

This reads: take whatever is in memory under the name “local_time”, multiply it by 60, and put it in memory under the name “local_time”.

Step 4. Wait

Now I’ll need that time module that I loaded in step 0:

time.sleep(local_time)

This reads: From module “time,” take the method “sleep.” From memory, find a piece of data under the name “local_time.” Give that piece of data to “sleep” and see what happens.

What happens: I have a number of seconds in ‘local_time’. I give that number to ‘Sleep,’ and the program sleeps for the specified number of seconds. I know it sleeps because I had read the reference manual for the module’ time’.

Step 5. Remind

Remember that I have our reminder text stored in memory under the name ‘text’? It’s time to use it:

print(text)

This means: take whatever is in memory under ‘text’ and send it to output. 

Similar to step 1, U could have set up a whole different implementation of sending out messages. I could have created a routine that 3D-prints our message in plastic or lights up some LEDs in the form of our text. But all I need now is this primary mechanism that sends out the text.

Final code

This is the code that will work:

import time
print("What shall I remind you about?")
text = str(input())
print("In how many minutes?")
local_time = float(input())
local_time = local_time * 60
time.sleep(local_time)
print(text)

If you input this into your Jupyter notebook and run (Shift + Enter), you’ll see your program in action: 

And if you want more practice on Python you can try our free course on Practicum by Yandex.