def before_all(context): """ """ # get logger context.log = logging.getLogger('twilio-ec2.Behave') # create file handler which logs even debug messages # overwrite the old log file fh = logging.FileHandler(filename='reports/behave.log', mode='w') # create console handler with a higher log level context.log.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.INFO) fh.setLevel(logging.DEBUG) # create formatter and add it to the handlers formatter = logging.Formatter('[%(asctime)s] [%(name)s] [%(levelname)s]: %(message)s', "%a %Y-%m-%d %H:%M:%S %z") ch.setFormatter(formatter) fh.setFormatter(formatter) context.log.addHandler(ch) context.log.addHandler(fh) #if not context.config.log_capture: #logging.basicConfig(level=logging.DEBUG) # get a connection to local sqlite3 twilio.db managed by flaskrilio script context.db = FlaskrilioDBHandler(db_conn=connect_db(), logger=context.log) ########################################################################## # configure FlaskrilioHandler if os.environ.get('MODE') is not None: if os.environ['MODE'] == 'EC2': from helpers.common import get_public_ip context.flaskip = get_public_ip() context.flaskport = 80 context.flaskhost = "http://%s:%d" % (context.flaskip, context.flaskport) context.publichost = "http://%s:%d" % (context.flaskip, context.flaskport) else: context.flaskip = "127.0.0.1" context.flaskport = 5000 context.flaskhost = "http://%s:%d" % (context.flaskip, context.flaskport) # Provide a publicly available host serving Twimls when running locally if os.environ.get('NGROK') is not None: context.publichost = os.environ.get('NGROK') else: context.publichost = "http://54.247.15.37" context.log.debug("PUBLIC HOST set to: %s" % context.publichost) context.fh = FlaskrilioHandler(hostname="%s" % (context.flaskhost), logger=context.log) ########################################################################## ########################################################################## # configure CallConnectHandler if os.environ.get('ENV') is not None: if os.environ['ENV'] == 'POC': cchost = "http://callconnect.poc.hibulabs.co.uk" elif os.environ['ENV'] == 'DEV': cchost = "http://callconnect.dev.hibulabs.co.uk" elif os.environ['ENV'] == 'USPROD': cchost = "http://callconnect.dev.hibulabs.co.uk" else: cchost = "http://callconnect.dev.hibulabs.co.uk" context.cch = CallConnectHandler(hostname=cchost, logger=context.log) ########################################################################## ########################################################################## # configure TwilioHandler context.th = TwilioHandler(logger=context.log) context.th.load_config(twilio_config="twilio.cfg") context.th.connect_to_twilio()
request.form.get('Direction'), \ request.form.get('CallStatus'), \ duration]) g.db.commit() log.debug("callSid:'%s' successfully added to db" % request.form.get('CallSid')) return "", 204 @app.route('/calls', methods=['GET']) def show_calls(): cur = g.db.execute('select * from calls order by id desc') calls = dict_from_row(cur) log.debug("Calls in DB:\n") for c in calls: log.debug(c) return jsonify({'calls': calls}) if __name__ == '__main__': if os.environ.get('MODE') is not None: if os.environ['MODE'] == 'EC2': from helpers.common import get_public_ip ip = get_public_ip() init_db() print "My public IP address is: %s" % ip app.run(host='0.0.0.0', port=80) else: init_db() app.run(debug=True)
request.form.get('CallSid'), \ request.form.get('Direction'), \ request.form.get('CallStatus'), \ duration]) g.db.commit() log.debug("callSid:'%s' successfully added to db" % request.form.get('CallSid')) return "", 204 @app.route('/calls', methods=['GET']) def show_calls(): cur = g.db.execute('select * from calls order by id desc') calls = dict_from_row(cur) log.debug("Calls in DB:\n") for c in calls: log.debug(c) return jsonify({ 'calls' : calls }) if __name__ == '__main__': if os.environ.get('MODE') is not None: if os.environ['MODE'] == 'EC2': from helpers.common import get_public_ip ip = get_public_ip() init_db() print "My public IP address is: %s" % ip app.run(host='0.0.0.0', port=80) else: init_db() app.run(debug=True)
def before_all(context): """ """ # get logger context.log = logging.getLogger('twilio-ec2.Behave') # create file handler which logs even debug messages # overwrite the old log file fh = logging.FileHandler(filename='reports/behave.log', mode='w') # create console handler with a higher log level context.log.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.INFO) fh.setLevel(logging.DEBUG) # create formatter and add it to the handlers formatter = logging.Formatter( '[%(asctime)s] [%(name)s] [%(levelname)s]: %(message)s', "%a %Y-%m-%d %H:%M:%S %z") ch.setFormatter(formatter) fh.setFormatter(formatter) context.log.addHandler(ch) context.log.addHandler(fh) #if not context.config.log_capture: #logging.basicConfig(level=logging.DEBUG) # get a connection to local sqlite3 twilio.db managed by flaskrilio script context.db = FlaskrilioDBHandler(db_conn=connect_db(), logger=context.log) ########################################################################## # configure FlaskrilioHandler if os.environ.get('MODE') is not None: if os.environ['MODE'] == 'EC2': from helpers.common import get_public_ip context.flaskip = get_public_ip() context.flaskport = 80 context.flaskhost = "http://%s:%d" % (context.flaskip, context.flaskport) context.publichost = "http://%s:%d" % (context.flaskip, context.flaskport) else: context.flaskip = "127.0.0.1" context.flaskport = 5000 context.flaskhost = "http://%s:%d" % (context.flaskip, context.flaskport) # Provide a publicly available host serving Twimls when running locally if os.environ.get('NGROK') is not None: context.publichost = os.environ.get('NGROK') else: context.publichost = "http://54.247.15.37" context.log.debug("PUBLIC HOST set to: %s" % context.publichost) context.fh = FlaskrilioHandler(hostname="%s" % (context.flaskhost), logger=context.log) ########################################################################## ########################################################################## # configure CallConnectHandler if os.environ.get('ENV') is not None: if os.environ['ENV'] == 'POC': cchost = "http://callconnect.poc.hibulabs.co.uk" elif os.environ['ENV'] == 'DEV': cchost = "http://callconnect.dev.hibulabs.co.uk" elif os.environ['ENV'] == 'USPROD': cchost = "http://callconnect.dev.hibulabs.co.uk" else: cchost = "http://callconnect.dev.hibulabs.co.uk" context.cch = CallConnectHandler(hostname=cchost, logger=context.log) ########################################################################## ########################################################################## # configure TwilioHandler context.th = TwilioHandler(logger=context.log) context.th.load_config(twilio_config="twilio.cfg") context.th.connect_to_twilio()