コード例 #1
0
from customer_model import db, Customer

# tell logger where to save
LOG_FILE = datetime.datetime.now().strftime('%Y-%m-%d') + '.log'
FH = logging.FileHandler(LOG_FILE)
# tell logger how to save each row
LOG_FORMAT = "%(asctime)s %(filename)s:%(lineno)-3d %(levelname)s %(message)s"
FORMATTER = logging.Formatter(LOG_FORMAT)
FH.setFormatter(FORMATTER)
# get that f****r going
logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger()
LOGGER.addHandler(FH)

Customer.drop_table()
Customer.create_table()


def add_customer(_name, _last_name, _home_address, _phone_number,
                 _email_address, _status, _poverty_score):
    '''add new customer function.'''
    try:
        with db.transaction():
            new_customer = Customer.create(name=_name,
                                           last_name=_last_name,
                                           home_address=_home_address,
                                           phone_number=_phone_number,
                                           email_address=_email_address,
                                           status=_status,
                                           poverty_score=_poverty_score)
            new_customer.save()
コード例 #2
0
def create_customer_table():
    """ create Customer table if not exists """
    with database:
        Customer.create_table()
    logger.info('Customer table create successful')
    database.close()