View Single Post
Posts: 6 | Thanked: 2 times | Joined on Jun 2010 @ Sweden
#1
Please give me some feedback on my code, hope you have some useful tips, first time i using python :-)

Why:
I wanted to know who was calling even if i didn't have them in my abook.

So far:
I got a python script, that lisen for incoming calls on dbus.

When it gets a number it ask my webserver for the name of that number (my server ask a few swedish sites for the name of the number) and return the name to python

Python then makes a Notification whit the name.

Left to do:
* Id like this to be run in background somehow, having it in a terminal work nice for debuging, but i prefer somthing less visible later.
* The notification is showing a icon, a paper whit a red X, id like to repalce this icon.
* When i click the notification, somthing should happen, but i don't know what id like it to yet.

Code:
Code:
#! /usr/bin/env python2.5
# -*- coding: utf-8 -*-

import gobject, dbus
import time
import os
from dbus.mainloop.glib import DBusGMainLoop

def handle_call(obj_path, callernumber):
	global blocklist
	print 'Calling from '+callernumber+'...'
	import urllib
	webFile = urllib.urlopen('http://nummer.tejpweb.se/nummer/?nummer='+callernumber)
	name = webFile.read()
	print name + ' is calling.'
	import pynotify
	pynotify.init( name )
	n = pynotify.Notification(name, "Call from " + name)
	n.set_urgency(pynotify.URGENCY_CRITICAL)
	n.show()

DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(handle_call, path='/com/nokia/csd/call', dbus_interface='com.nokia.csd.Call', signal_name='Coming')
gobject.MainLoop().run()
 

The Following User Says Thank You to puggan For This Useful Post: