<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
hi all,<br>I see mod_python in wiki and i try to make some example as page: http://wiki.freeswitch.org/wiki/Examples_directory_py<br><br>i have configure in dial plan as:<br>&lt;extension name="directory"&gt;<br>&nbsp; &lt;condition field="destination_number" expression="^1234$"&gt;<br>&nbsp;&nbsp;&nbsp; &lt;action application="python" data="directory"/&gt;<br>&nbsp; &lt;/condition&gt;<br>&lt;/extension&gt;<br><br>and in /usr/local/freeswitch/scripts/<br>add file directory.py as:<br><br><pre>import sys, time, sqlite3<br>from freeswitch import *<br><br>digitpath = "/usr/local/freeswitch/sounds/en/us/callie/digits/8000/"<br>custom_sounds_path = "/usr/local/freeswitch/sounds/custom/"<br><br>def checkforgreeting(extension):<br>    conn = sqlite3.connect("/usr/local/freeswitch/db/voicemail_default.db")<br>    c = conn.cursor()<br>    c.execute("select name_path from voicemail_prefs where username=?", (extension,) )<br>    # retrieve recorded_name path<br>    row=c.fetchone()<br>    console_log("alert", "row:&nbsp;%s\n"&nbsp;% (str(row)))<br>    c.close()<br>    if row[0]:<br>        return row<br>    else:<br>        return False<br>       <br>def handler(uuid):<br><br>    alphabet = "abcdefghijklmnopqrstuvwxyz"<br>    numbers = "22233344455566677778889999"<br>    <br>    code_to_name = {}<br>    code = ""<br>    <br>    names = { <br>        "Allen, Larry": 1000,<br>        "Monroe, Beckey": 1001,<br>        }<br>    <br>    lnames = {}<br>    <br>    for name in names:<br>        lnames[name.lower()] = names[name]<br>    <br>    names = lnames<br>    <br>    def sayname(fullname):<br>        console_log("alert", "Now saying: " + fullname + "\n")<br>        # flip first and last... remove comma<br>        split_fullname = fullname.split(',')<br>        fname_lname = split_fullname[1].lstrip() + " " + split_fullname[0]<br>        # take the chars of a name and say each one<br>        session.execute("phrase", "spell," + fname_lname);<br>    <br>    <br>    # preprocessing before evaluating arg input<br>    # build codes from names dict<br>    for name in names:<br>        name3char = name[0:3]<br>        # empty out the code var<br>        code = ""<br>        for char in name3char:<br>            code = code + numbers[alphabet.index(char)]<br>        # code is the 3 digits code generated from the first 3 chars of the last name<br>        if not code in code_to_name:<br>            code_to_name[code] = [ name ]<br>        else:<br>            code_to_name[code].append(name)<br><br>    session = PySession(uuid)<br>    session.answer()<br>    session.execute( "sleep", "2000" )<br>    digits_keyed = session.playAndGetDigits(3,<br>                                            3,<br>                                            10,<br>                                            5000,<br>                                            "*#",<br>                                            custom_sounds_path + "dir-intro.wav",<br>                                            "",<br>                                            "");<br>    # evaluate input<br>    # we want 3 digits<br>    console_log("alert", "digits_keyed:&nbsp;%s\n"&nbsp;% ( str(digits_keyed) ))<br>    if len(digits_keyed) == 3:<br>        # it must be in the code db generated from last names earlier<br>        if digits_keyed in code_to_name:<br>            console_log("alert", "Yes:&nbsp;%s\n"&nbsp;% (str(code_to_name[digits_keyed])))<br>            if len(code_to_name[digits_keyed]) == 1:<br>                # only one extension matches<br>                console_log("alert", "Extension found:&nbsp;%s\n"&nbsp;% ( str(names[code_to_name[digits_keyed][0]])))<br>                # transfer to the extension<br>                extension = str(names[code_to_name[digits_keyed][0]])<br>                recorded_name = checkforgreeting(extension)<br>                if recorded_name:<br>                    console_log("alert", "Saying recorded name\n")<br>                    session.streamFile( str(recorded_name[0]) )<br>                else:<br>                    sayname(code_to_name[digits_keyed][0])<br>                session.execute("phrase", "spell," + extension);<br>                session.execute( "sleep", "1000" )<br>                # give option of if correct to press 1 otherwise * and start over<br>                digits_keyed = session.playAndGetDigits(1,<br>                                                        1,<br>                                                        3,<br>                                                        2000,<br>                                                        "#",<br>                                                        custom_sounds_path + "dir-instr.wav",<br>                                                        "",<br>                                                        "1|\*");<br>                console_log("alert", "digits_keys:&nbsp;%s\n"&nbsp;% ( digits_keyed ))<br>                if digits_keyed == "1":<br>                    session.transfer( extension, "XML", "default")<br>                else:<br>                    if digits_keyed == "*":<br>                        session.streamFile( custom_sounds_path + "dir-nomatch.wav" )<br>                        handler(uuid)<br>                        # session.transfer( "777", "XML", "default")<br>                        # session.hangup("1")<br><br>            else:<br>                # we matched more than one name<br>                for item in code_to_name[digits_keyed]:<br>                    console_log("alert", "Found more than one extension:&nbsp;%s\n"&nbsp;% ( str(names[item])))<br>                    # say each one and give option of if not that one to continue<br>                    console_log("alert", "item:&nbsp;%s\n"&nbsp;% (item))<br>                    extension = str(names[item])<br>                    recorded_name = checkforgreeting(extension)<br>                    if recorded_name:<br>                        session.streamFile( str(recorded_name[0]) )<br>                    else:<br>                        sayname(item)<br>                    session.execute("phrase", "spell," + extension);<br>                    session.execute( "sleep", "1000" )<br>                    # give option of if correct to press 1 otherwise * and start over<br>                    digits_keyed = session.playAndGetDigits(1,<br>                                                            1,<br>                                                            3,<br>                                                            2000,<br>                                                            "#",<br>                                                            custom_sounds_path + "dir-instr.wav",<br>                                                            "",<br>                                                            "1|\*");<br>                    console_log("alert", "digits_keys:&nbsp;%s\n"&nbsp;% ( digits_keyed ))<br>                    if digits_keyed == "1":<br>                        session.transfer( extension, "XML", "default")<br>                        # session.hangup("1")<br>                session.streamFile( custom_sounds_path + "dir-nomore.wav" )<br>                handler(uuid)<br>                # session.transfer("777", "XML", "default")<br>                # session.hangup("1")<br>        else:<br>            # no valid extension found so transfer back<br>            session.streamFile( custom_sounds_path + "dir-nomatch.wav" )<br>            handler(uuid)<br>            # session.transfer("777", "XML", "default")<br>            # session.hangup("1")<br><br>    session.hangup("1")<br><br><br>i log in soft phone and make call to :1234<br>==========&gt;<br><br>call hangup and i see log in freeswitch -c:<br><br>2010-12-10 02:35:55.711484 [ERR] mod_python.c:200 Error calling python script<br>TypeError: handler() takes exactly 1 argument (2 given)<br>Traceback (most recent call last):<br>  File "&lt;string&gt;", line 1, in &lt;module&gt;<br>NameError: name 'python_makes_sense' is not defined<br><br>please suggest to fax it and make it work.<br>another thing:<br><br>if i have mysql database, how can i get value from mysql.<br>example: i have table test in fusionpbx database.<br><br>mysql&gt; select * from test;<br>+----+------+----------+-------------+<br>| id | user | password | ms          |<br>+----+------+----------+-------------+<br>|  1 | 123  | 12345678 | 87546345634 |<br>+----+------+----------+-------------+<br><br>so: how can i get value password = 12345678 when i enter user =123 (in python code). <br><br>thanks all so much<br><br></pre><br><br><br><br>                                               </body>
</html>