Birthday reminder app in Python



# Python program for
# Birthday reminder app

 
# the time module should be a reminder
# set using dates

import time

 
# the os module is used to notify the user
# using the notification bar & quot; Ubuntu & quot; default

import os

 
# Birthday file where actual birthdays
# and dates are present. This file can be
# manually edited or automated.
# We`ll edit it for simplicity manually.
# Birthdays must be written in this file in
# format: & quot; Last name Name of the month & quot; (without quotes)

 

birthdayFile = `/ path / to / birthday / file`

  

def checkTodaysBirthdays ():

fileName = open (birthdayFile, `r` )

today = time.strftime ( `% m% d` )

  flag = 0

for line in fileName:

if today in line:

  line = line.split ( `` )

flag = 1

# line [ 1] contains the first name and line [2] contains the last name

os.system ( `notify-send" Birthdays Today: ` + line [ 1 ]

+ `` + line [ 2 ] + `" ` )

if flag = = 0 :

os.system ( `notify -send "No Birthdays Today!" ` )

  

if __ name__ = = `__main__` :

checkTodaysBirthdays ()

Adding a script to autoload

After writing the above code, it`s time to add this Python script to run. This can be done in Ubuntu as follows:

  1. First, we need to create an executable file for our remder.py script
  2. This can be done by typing the following command in the terminal
      sudo chmod + x reminder.py , where reminder.py is our script file name 
  3. Now we need to transfer this file along the path where Linux looks for default files:
    Enter this command in a terminal:
      sudo cp /path/to/our/reminder.py / usr / bin  

    This will add our executable script to / usr / bin.

  4. In the global search, search for Startup Applications
  5. Click on Add and give the desired name for your process
  6. Enter the command. For example, our filename —  filederder.py, then enter remder.py in the command field and select Add.

NOTE . The script runs automatically (after being added to startup) every time the system starts. Also, if you have more than two birthdays on the same day, both notifications will be notified in a notification.

What the birthday file should look like

Output after script run

This article is provided by Omkar Pathak . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting the article [email protected] ... See my article appearing on the Python.Engineering homepage and help other geeks.

Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.