maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   General (https://talk.maemo.org/forumdisplay.php?f=7)
-   -   Caller name, online fetching, python, dbus (https://talk.maemo.org/showthread.php?t=56083)

puggan 2010-06-13 16:57

Caller name, online fetching, python, dbus
 
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()


oakbeach 2010-06-13 20:19

Re: Caller name, online fetching, python, dbus
 
Hi,

I'm looking forward following the thread hopefully learning a bit of python.. I made some similar efforts myself a couple of weeks ago.

picked up some code from the python callblocker script.
and parsed eniro.se. then i got stuck on using urllib as I'm a newbie py




Rgrds,
oakbeach

ToJa92 2010-06-13 20:32

Re: Caller name, online fetching, python, dbus
 
Wow, this could prove useful since I also live in Sweden :D
I'll be monitoring this thread.

puggan 2010-06-13 21:19

Re: Caller name, online fetching, python, dbus
 
Quote:

Originally Posted by ToJa92 (Post 713589)
Wow, this could prove useful since I also live in Sweden :D
I'll be monitoring this thread.

at my server Im using hitta,se and vemringde.se as source, and a cache on my server, your welcome to use my server as source to.

hope i can learn some of what lirtex was doing on the same subject:
http://talk.maemo.org/showthread.php?t=56088

Quote:

Originally Posted by lirtex (Post 713430)
What I did so far:
  1. Created a daemon that detects incoming calls.
  2. The daemon then checks if the incoming call number exists in the phone contacts.
  3. If it isn't -- it gets the number identification from the net (using libcurl).

Id like to use 1 and 2 above in my project to.

qwerty12 2010-06-13 23:51

Re: Caller name, online fetching, python, dbus
 
Quote:

Originally Posted by puggan (Post 713377)
* 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:

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

import os
import sys
import gobject, dbus
import pynotify
from dbus.mainloop.glib import DBusGMainLoop

def cb (Notification=None, action=None, Data=None):
        pass

DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
pynotify.init(os.path.splitext(os.path.basename(sys.argv[0]))[0])
n = pynotify.Notification("Mail, mother****er!", "Call from Beelzebub", "general_clock")
n.set_hint_string("dbus-callback-default", "com.nokia.osso_browser /com/nokia/osso_browser com.nokia.osso_browser open_new_window string:\"callto://666\"")
n.add_action("default", "call", cb)
n.show()

Alas, Hildon Desktop is incredibly stupid and will only call services registered on the Session bus, so I had go through the browser.

droll 2014-02-07 09:16

Re: Caller name, online fetching, python, dbus
 
on a related note, does anyone know how to capture dbus events and have it trigger a shell script? this could be easily done on N900. is there a similar directory where i can install a shell script that gets called during dbus events?


All times are GMT. The time now is 23:16.

vBulletin® Version 3.8.8