Wednesday, October 9, 2013

'remindme.py' A Simple Python Script To Remind You About Events That You Want To Remember | Pranshu

Written by  | Google+ Pranshu Bajpai | LinkedIn

This is a simple Linux utility that I coded long ago for personal use that would remind me about events that I want to remember. It reminds you of a given event on a certain data after you log onto your computer on that date.

This is a basic script in Python. Please feel free to improve it to suit your particular needs.

Functionality:

-Displays a Graphical Notification in Top Right Corner Each Time you Login
-You Manually Enter Events and Corresponding dates

How to Use:

Create a Folder called "python codes" in your root directory and place "remindme.py" there

(Path is hard coded in the script. This is bad coding, but I was in a hurry. Like I said, feel free to improve the code)

Create a File in this folder called "remindme.data"

Enter the Dates and Events in this format and Save:

MonthDay Event
Example for 10th of Oct:
1010 EventName



Add remindme.py to 'Startup'  (Applications -> System Tools -> Preferences -> Startup)



(I have added a module for 'Auto-Add to Startup' but it was giving issues, so I commented it out, feel free to correct that)

Each Time you login now, remindme will check the remindme.data file and see if there's an Event listed for today. If an event is listed, it will display a notification:




If you're new to Python you might like to read the code:

#!/usr/bin/python

import time       #for checking current date
import gtk.gdk    
import pynotify   #For Notifications

today = time.strftime("%m%d")
Remind_Me_Path = "python /root/python\ codes/remindme.py"  #Path to script


#Following Function that checks whether Startup Entry is already made
#Coz We don't want multiple startup entries made, everytime program runs

def check_startup_entry():                   
 flag = 0
 file = open ("/root/.bash_profile", 'r')
        for line in file:
                if Remind_Me_Path in line:
   flag = 1
 if flag == 0:
  add_to_startup()  

#Following Function adds the startup entry if it check_startup didn't find one

def add_to_startup():
 file = open ("/root/.bash_profile", 'a+')
 file.write(Remind_Me_Path)
 file.write("\n")
 file.close() 

#Following Function checks for Events in Remind_Me.data file

def check_for_event():
 file = open ("/root/python codes/remindme.data", 'r')
 for line in file:
  if today in line:
   notify(line)
 file.close()


#Following Function is called by check_for_event for notification

def notify(arg):
 pynotify.init("Basic")
 n = pynotify.Notification("Remind_Me: " + arg)
 n.set_hint('x', gtk.gdk.screen_width()/2.)
 n.set_hint('y', gtk.gdk.screen_height()/2.)
 n.show()

check_startup_entry()
check_for_event()

4 comments: