Create a Birthday Reminder in Python

In this tutorial, we will know how to create a Birthday Reminder in Python.

Creating a Birthday Reminder Application in Python

We will learn how to build a birthday reminder application using the Python programming language. It will help us to remind birthdays and notify us about our beloved ones’ birthdays. We implement Python in Ubuntu operating system environment to do this task so as to remind the users on every start of the system. In order to create a Birthday Reminder in Python, we follow the below steps.


Sample Code:

Below is a simple implementation of python code to build a birthday reminder application.

# Python program For Birthday Reminder Application
import time
import os
myBrthdayFile = '/path/to/birthday/file'
def checkBirthdays():
 myBirthdayFileName = open(myBirthdayFile, 'r')
 today = time.strftime('%m%d')
 z = 0
 for i in myBirthdayFileName:
  if today in i:
   i = i.split(' ')
   z =1
   os.system('notify-send "Its the birthday of" + i[1] + '_' + i[2])
 if z == 0:
  os.system('notify-send "Oh!No Birthday!"')
if __name__ == '__main__':
 checkBirthdays()

 

How to Add the script?

On writing the above python code, we then need to add it to the startup in Ubuntu. This is done as follows:

  • At first, we create an executable file for our birthdayReminder.py script. This birthdayReminder.py script is our python script filename. This is done by the following command in our ubuntu terminal.

sudo chmod +x birthdayReminder.py

  • Then we transfer the file to the path where Linux searches for its default files by typing the following command in the Ubuntu terminal. Executable script -> /usr/bin.

sudo cp /path/to/our/reminder.py /usr/bin

  • Now in global search, we have to search for the Startup Applications.
  • Then we click on Add and provide the desired name to our process by typing the command. For instance, we have our file name as birthdayReminder.py, so we type birthdayReminder.py in the command field and then select Add.

The birthday file:

birthdayReminder.data

1229 Ria Singh
0514 Kartik Mittal
0219 Amrit Jha

Output:

Its the birthday of Kartik_Mittal

Hence we will create a Birthday Reminder in Python which will notify us of the birthday of people we have saved for as a reminder. This is the best way to do it in Ubuntu.

Know: Time module in Python

Leave a Reply

Your email address will not be published.