[growlcid] / growlcid.py Repository:
ViewVC logotype

View of /growlcid.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (download) (as text) (annotate)
Fri Jun 2 04:52:54 2006 UTC (3 years, 5 months ago) by synack
File size: 2718 byte(s)
Initial import
#!/usr/bin/env python

"""Caller ID notifier for growl"""
__version__ = "$Revision: 1.7 $"
__author__ = "Jeremy Grosser (http://www.neohippie.net/)"
__copyright__ = "(C) 2006 Jeremy Grosser. Code uner BSD License."
__contributors__ = "Rui Carmo (netgrowl.py)"

################ CONFIGURATION ################
# The destination to send growl notifications to. Set to "<broadcast>" if you
# want notifications to be sent out to the local subnet.
DESTINATION="<broadcast>"

# The password to send growl notifications with. For growlcid to work, this must
# be the same as the Server password set in the network tab of the growl
# preference pane.
GROWL_PASSWORD="rtz2096"

# The device your modem can be found at. The following suggestions should work
# in most situations
# Linux:	/dev/ttyS0
# Mac OSX:	/dev/tty.modem
# FreeBSD:	/dev/cuaa0
SERIAL_DEV="/dev/tty.modem"

# Don't forget to turn on network notifications in the growl preference pane.

################## CHANGELOG ##################
# $Log: growlcid.py,v $
# Revision 1.7  2006/05/03 13:14:35  synack
# Moved serial device to variable
#
# Revision 1.6  2006/05/03 09:04:02  synack
# Cleaned up control logic in the while loop
#
# Revision 1.5  2006/05/03 08:39:09  synack
# Changed ID to revision
#
# Revision 1.4  2006/05/03 08:38:32  synack
# Added CVS keywords
#

import netgrowl;
import socket;
import serial;
import sys;

# Open a udp socket... Don't worry, it won't timeout
addr = (DESTINATION, netgrowl.GROWL_UDP_PORT)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

if DESTINATION == "<broadcast>":
	s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)

reg = netgrowl.GrowlRegistrationPacket(application="Caller ID", password=GROWL_PASSWORD)
reg.addNotification("Incoming call", enabled=True)
s.sendto(reg.payload(), addr)

# Open the serial port
ser = serial.Serial(SERIAL_DEV, 9600, timeout=1)

# Make sure the serial port is connected to an AT modem and put it in CID mode
ser.write("AT")
if(ser.readline()== "AT"):
	ser.write("AT#CID=1")
	ser.readline()
else:
	print "Modem not responding to AT commands"
	s.close()
	ser.close()
	sys.exit(0)


# Setup some storage and enter the main loop
number = ""
name = ""
while 1:
	#line = ser.readline()
	line = sys.stdin.readline()
	if(line[:4] == "NMBR"):
		number = line[7:]
	elif(line[:4] == "NAME"):
		name = line[7:]

	if(number and name):
		msg = name + "(" + number[:3] + ") " + number[3:6] + "-" + number[6:-1]
		p = netgrowl.GrowlNotificationPacket(application="Caller ID",
			notification="Incoming call", title="Incoming call",
			description=msg, sticky=False,
			password=GROWL_PASSWORD)

		s.sendto(p.payload(), addr)
		number = ""
		name = ""

# Cleanup
s.close()
ser.close()

synack at csh.rit.edu
ViewVC Help
Powered by ViewVC 1.0.0