def get_data(self, ac): self.query = "select bal from bank where account = %s" % ac print self.query self.df = txdb.execute(self.query) self.df.addCallback(self.on_db) self.df.addErrback(self.err_db) return self.df
def get_data(self): """Retrieve balance from the database.""" self.query = "select bal from bank where account = %s" % ac print self.query self.df = txdb.execute(self.query) self.df.addCallback(self.on_db) self.df.addErrback(self.err_db)
def doStart(self): log.debug('Start processing on call') try: destination_number = self.inbound_call_info['Caller-Destination-Number'] context = self.inbound_call_info['Channel-Context'] caller_direction = self.inbound_call_info['Caller-Direction'] caller_number = self.inbound_call_info['Caller-Orig-Caller-ID-Number'] # create call object in redis. call_obj = createCallObj(ph=caller_number, uuid=self.uuid, action='inbound_call', action_args=None) log.debug('Call object created : %s' % call_obj) call_obj.web_hook_url = self.web_hook_url self.increment_call() log.debug('Required Call information context : %s, caller-dire : %s, dest-num : %s' %(context, caller_direction, destination_number)) self.set_channel_variables(caller_number) query = "select * from input_actions inner join ivr on input_actions.ivr_id= ivr.id " \ "where ivr.destination_number='%s'" % destination_number # query = "select * from input_actions where ivr_id = 1" log.debug('Query run to be : %s' % query) db_data = yield txdb.execute(query) log.debug('Query response : {}'.format(db_data)) self.call_detail_dict = final_data = self.query_result_to_dict(db_data) query_web_hook = "select * from web_hook inner join ivr on web_hook.ivr_id= ivr.id " \ "where ivr.destination_number='%s'" % destination_number log.debug('Query run to be : %s' % query_web_hook) web_hook_db_data = yield txdb.execute(query_web_hook) log.debug('Query response : {}'.format(web_hook_db_data)) if web_hook_db_data: self.web_hook_url = web_hook_db_data[0].get('url') log.debug('Web hook url : %s' % self.web_hook_url) else: log.error('web hook url not found.') self.web_hook_url = 'nothing found' log.debug('Database result convert to dict : %s' % final_data) if final_data: # self.check_number_and_play_ivr(destination_number) df = self.call_listen.start() df.addCallback(self.call_response_success, message='call listen start') df.addErrback(self.call_response_fail, message='call listen start') else: log.error('Call not match with required condition to process further.') self.channel_hangup() return except KeyError as e: log.error('Error captured at fetch call information : %s' % e) self.channel_hangup() return
def update_data(self): """Update the balance in database.""" self.query = "update bank set bal = %s where account = %s" % (val, ac) print self.query self.df = txdb.execute(self.query) self.df.addCallback(self.new_data) self.df.addErrback(self.err_db) return self.df
def on_verify(self): """Check if the account number exist in the database.""" self.query = "select account from bank where account = %s" \ % account_num self.df = txdb.execute(self.query) self.df.addCallback(self.on_check) self.df.addErrback(self.err_db) return self.df
def insert_into_db(self): query = """insert into cdrdb values(calldate, dst, dcontext, channel, dstchannel, lastapp, duration, disposition, uniqueid) values (%s, %s, %s, %s, %s, %s, %s, %s, %s)""" % ( start, self.exten, self.context, cdr[1].get('channel'), cdr[2].get('channel'), cdr[1].get('applications'), self.duration, self.disposition, self.uniqueid) print query df = txdb.execute(query, val) df.addCallback(onDb) df.addErrback(errDb)
def insert_into_db(self, event): print(call_details) query = """insert into cdrdb (calldate, recording, dst, dcontext, channel, dstchannel, lastapp, duration, disposition, uniqueid) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')""" % ( start, path, call_details['extension'], call_details['context'], cdr[1].get('channel'), cdr[2].get('channel'), cdr[1].get('application'), call_details['duration'], call_details['disposition'], call_details['uniqueid']) print(query) df = txdb.execute(query) df.addCallback(self.on_finish) df.addErrback(self.err_db)
def getUserFromDb(self, request): global requests requests = request if clicktocall.uid == 0: requests.write(''' <html><body> <br>CALL REJECTED <br> </body></html> ''') requests.finish() else: query = "select * from cdr where uniqueid = %s or \ uniqueid = %s" % (clicktocall.uid, clicktocall.uid2) print query df = txdb.execute(query) df.addCallback(self.onDb) df.addErrback(self.errDb)
def get_user_from_db(self, request): """Retrieves call record from database""" global requests requests = request """ if clicktocall.uid1 == 0: requests.write(''' <html><body> <br>CALL REJECTED <br> </body></html> ''') requests.finish() else: """ query = "select * from cdrdb where uniqueid = '%s'" % clicktocall.uid print query df = txdb.execute(query) df.addCallback(self.on_db) df.addErrback(self.err_db)
def main(): query = 'select account from bank' df = txdb.execute(query) df.addBoth(output)
df.addCallback(onGetData) df.addErrback(errGetData) def onGetData(result): print("In getData") print(result) if not result: return errGetData() user_id = result return getUserFromDb(user_id) def getUserFromDb(user_id) query = "select * from table where id = %s" % result df = txdb.execute(query) df.addCallback(onDb) df.addErrback(errDb) def errGetData(error=None): print("Erorr in get data") print(error) def onDeb(result): print("reslt db") print(result) if not result: return errDb(None)
def getUserFromDb(user_id): query = "select account from bank where id = %s" % user_id print query df = txdb.execute(query) df.addCallback(onDb) df.addErrback(errDb)
def getUserFromDb(self, digits): self.query = "select account from bank where id = %s" % digits print self.query df = txdb.execute(self.query) df.addCallback(self.onDb) df.addErrback(self.errDb)