Example #1
0
class Equip(Item):
    def __init__(self, name):
        self.name = name
        self.tiles = []
        self.color = random.randint(0, 3)
        self.db = DBHelper()
        self.generate_tiles()

    def generate_tiles(self):
        total_tiles = self.db.get_tile()
        count = 8
        if self.color == 0:
            count = 10
        if self.color == 1:
            count = 7
        while count > 0:
            count -= 1
            i = random.randint(0, len(total_tiles) - 1)
            self.tiles.append(total_tiles[i])

    def __str__(self):
        str = self.name
        str += '\n'
        for tile in self.tiles:
            str += '[%s]%s\n' % (tile.name, tile.desc)
        return str
Example #2
0
class Account(object):
    def __init__(self, username, password, status=0):
        self.id = 0
        self.username = username
        self.password = password
        self.status = status
        self.db = DBHelper()

    def create(self):
        self.db.create_account(self)

    def login(self):
        if self.db.login(self):
            self.status = 1

    def list_role(self):
        roles = self.db.get_role(self)
        print(FMT_LIST_HEAD)
        if len(roles) == 0:
            print(STR_NO_ROLE)
        if len(roles) < 5:
            print(STR_ADD_ROLE)
        for i, role in enumerate(roles, 1):
            print(FMT_LIST_LINE)
            print(STR_LIST_ROLE % (i, role.name, role.career))
        print(FMT_LIST_HEAD)
        return roles

    def add_role(self, role):
        self.db.add_role(self, role)

    def __str__(self):
        return 'username: %s, password: %s, status: %s' % (
            self.username, self.password, self.status)
Example #3
0
def main():
    DBHelper().gen_schema()

    tornado.options.define("port", default=os.environ['PORT'] if 'PORT' in os.environ else 3000)
    # Specify whether the app should run in debug mode
    # Debug mode restarts the app automatically on file changes
    tornado.options.define("debug",
                           default=False if 'APP_ENV' in os.environ and os.environ[
                               'APP_ENV'] == 'production' else True)

    # Read settings/options from command line
    tornado.options.parse_command_line()

    # Access the settings defined
    options = tornado.options.options

    app = make_app(options)

    app.listen(os.environ["PORT"])
    tornado.ioloop.IOLoop.instance().start()
Example #4
0
import os

import db.db_connector as dbc
from db.db_helper import DBHelper

# These environment variables are configured in app.yaml.
CLOUDSQL_CONNECTION_NAME = os.environ.get('CLOUDSQL_CONNECTION_NAME')
CLOUDSQL_USER = os.environ.get('CLOUDSQL_USER')
CLOUDSQL_PASSWORD = os.environ.get('CLOUDSQL_PASSWORD')

db = dbc.connect_to_sql(CLOUDSQL_CONNECTION_NAME,
                        CLOUDSQL_USER,
                        CLOUDSQL_PASSWORD,
                        use_unicode=True,
                        charset="utf8")
dbhelper = DBHelper(db,
                    CLOUDSQL_CONNECTION_NAME,
                    CLOUDSQL_USER,
                    CLOUDSQL_PASSWORD,
                    use_unicode=True,
                    charset="utf8")
Example #5
0
 def __init__(self, name):
     self.name = name
     self.tiles = []
     self.color = random.randint(0, 3)
     self.db = DBHelper()
     self.generate_tiles()
 def __init__(self):
     self.db_helper = DBHelper("db_coffee_for_me.db")
class PositionsHelper:
    def __init__(self):
        self.db_helper = DBHelper("db_coffee_for_me.db")

    def get_all_salesmans(self):
        return self.db_helper.all_salesmans()

    def create_and_print_bill(self, sale_info_dict):
        columns, rows = [], []
        total_price, quantity, currency_type = self._get_total_price_and_currency_type_for_coffee(
            sale_info_dict)

        for key in sale_info_dict:
            if key == const.BILL:
                continue
            if type(sale_info_dict.get(key)) is list:
                columns.append(key)
                rows.append(f"{', '.join(sale_info_dict[key])}")
            else:
                columns.append(key)
                rows.append(sale_info_dict[key])
        columns.append("Total")
        rows.append(f"{total_price} {currency_type}")
        res = create_table(rows, columns)
        print(res)
        self._save_last_order_in_file(res)
        #     # what about empty additional ingredients(in bill)

    @staticmethod
    def _save_last_order_in_file(table):
        path_to_bill = Path(project_path_dir, "bill.txt")
        with path_to_bill.open(mode="w") as f:
            f.write(table)

    @staticmethod
    def _get_total_price_and_currency_type_for_coffee(sale_info_dict):
        coffee_with_price = sale_info_dict[
            "coffee type"]  # what if dont have ingredients
        quantity = sale_info_dict["quantity"]
        split_coffee_with_price = coffee_with_price.split()
        price_for_coffee = int(split_coffee_with_price[1])
        currency_type = split_coffee_with_price[-1]
        total_value_for_coffee = price_for_coffee * quantity
        return total_value_for_coffee, quantity, currency_type  # think about summ of diff currency

    def get_el_from_summary_table_by_username(self, column_name, name):
        res = self.db_helper.get_element_from_total_table_for_salesman(
            column_name, name)
        return 0 if not res else res

    def update_summary_table_by_name(self, column_name, name, sale_info_dict):
        curr_total, quantity, *rest = self._get_total_price_and_currency_type_for_coffee(
            sale_info_dict)
        if column_name == "total":
            new_total_value = self.get_el_from_summary_table_by_username(
                column_name, name) + curr_total
            self.db_helper.update_data_in_summary_table(
                column_name, name, new_total_value)
        elif column_name == "number_of_sales":
            new_number_of_sales_value = self.get_el_from_summary_table_by_username(
                column_name, name) + quantity
            self.db_helper.update_data_in_summary_table(
                column_name, name, new_number_of_sales_value)
def db():
    db = DBHelper()
    db.connect()
    yield db
    db.disconnect()
Example #9
0
 def __init__(self, username, password, status=0):
     self.id = 0
     self.username = username
     self.password = password
     self.status = status
     self.db = DBHelper()