Author Topic: insert user registered to database  (Read 349 times)

mahsa

  • Newbie
  • *
  • Posts: 1
    • View Profile
insert user registered to database
« on: June 19, 2018, 11:31:16 PM »
hi all; i want to write a piece of code in order to add(insert) a user to database who has been registered into a yate. here is my code, but is not working. can anyone help me what is the  problem with this?
thanks.


import MySQLdb
import pymysql
from twisted.internet.defer import Deferred,setDebugging
from twisted.internet import reactor, defer
from yaypm import TCPDispatcherFactory, AbandonedException
from yaypm.flow import go, getResult
from yaypm.utils import ConsoleFormatter
from time import sleep
from twisted import *
import logging, yaypm


logger = logging.getLogger("test3")

class myTest(object):

    def __init__(self, client):
        logger.debug(">>> myTest.__init__()")
        self.client = client
        self.run()
   
   
    def run(self):
        logger.debug(">>> myTest.run()")
        go(self.test())

    def test(self):
        logger.debug(">>> myTest.test()")

        yield self.client.onmsg("user.register", lambda m: m==m)
        register    =   getResult()
       
        logger.debug("register")           
        register.ret(True, "")

        db = pymysql.connect(host='localhost',user='***',password='***',db='mysql')
        cursor = db.cursor()
        logger.debug(">>> myTest.connect()")
       
        sql = "INSERT INTO call_logs (user_register) VALUES ('%s') "
       
        cursor.execute(sql,(register))
       
        db.commit()
        db.close()
       
     
     
def start(host, port):
    logger.debug("dans start")

    local_addr = remote_addr = host
    local_port = remote_port = port

    #go(route(yate))
    def start_client(client_yate):
        logger.debug("client started");
        myTest(client_yate)

    installSignalHandlers = 1
    client_factory = TCPDispatcherFactory(start_client)

    reactor.connectTCP(local_addr, local_port, client_factory)
##
hdlr = logging.StreamHandler()
formatter = ConsoleFormatter(' %(levelname)s %(message)s')
hdlr.setFormatter(formatter)

yaypm.logger.addHandler(hdlr)
yaypm.logger.setLevel(logging.DEBUG)
#yaypm.flow.logger_flow.setLevel(logging.DEBUG)
yaypm.logger_messages.setLevel(logging.DEBUG)
yaypm.logger_messages.setLevel(logging.INFO)

logger.setLevel(logging.DEBUG)
logger.addHandler(hdlr)
##

start("127.0.0.1", 5039)
reactor.run()