def module_test(): """Run the module test""" try: # Assume office PC and just try and connect to db database = BarDatabase("servcinf-sql", 3306) through_tunnel = False except MySQLdb.OperationalError: # If not, try and create a tunnel from ssh_tunnel import create_tunnel, close_tunnel create_tunnel() time.sleep(1) database = BarDatabase("127.0.0.1", 9000) through_tunnel = True #DATABASE.insert_user(1234567890128,"test2") username, id_ = database.get_user('test') print "For barcode 'test' fetch name '{}' and id '{}'".format(username, id_) print "For id {} fetch sum {}".format(id_, database.sum_log(id_)) database.cursor.execute('select * from fridays_items') for line in database.cursor.fetchall(): print line if through_tunnel: close_tunnel() time.sleep(1)
def module_test(): """Run the module test""" try: # Assume office PC and just try and connect to db database = BarDatabase("servcinf-sql", 3306) through_tunnel = False except MySQLdb.OperationalError: # If not, try and create a tunnel from ssh_tunnel import create_tunnel, close_tunnel create_tunnel() time.sleep(1) database = BarDatabase("127.0.0.1", 9000) through_tunnel = True #DATABASE.insert_user(1234567890128,"test2") username, id_ = database.get_user('test') print "For barcode 'test' fetch name '{}' and id '{}'".format( username, id_) print "For id {} fetch sum {}".format(id_, database.sum_log(id_)) database.cursor.execute('select * from fridays_items') for line in database.cursor.fetchall(): print line if through_tunnel: close_tunnel() time.sleep(1)
def main(): """Main function""" bar101 = Bar101() while True: bar101.start_up() try: bar101.run() except KeyboardInterrupt: bar101.clean_up() bar101.picaso.close() close_tunnel() break except: bar101.clean_up() close_tunnel() raise close_tunnel()