def __init__(self, telegram_id, id=None, name=None, age=None, gender=None, weight=0, bodyfatratio=0, c_chest=0, c_leg=0, c_waist=0, c_triceps=0): db = Database.get_instance() user = db.check_user(telegram_id) # try: self.id = user['id'] self.name = user['name'] self.age = user['age'] self.gender = user['gender'] self.telegram_id = user['telegram_id'] self.weight = user['measurements']['weight'] self.bodyfatratio = user['measurements']['bodyfatratio'] self.c_chest = user['measurements']['c_chest'] self.c_leg = user['measurements']['c_leg'] self.c_waist = user['measurements']['c_waist'] self.c_triceps = user['measurements']['c_triceps']
def setUp(self): self.database = Database.get_instance() cur = self.database.conn.cursor() cur.execute("""INSERT INTO core.users (id, name, age, gender, telegram_id, weight, bodyfatratio, c_chest, c_leg, c_waist, c_triceps) VALUES(0, 'test', 0, 'male', 0, 0, 0, 0, 0, 0, 0)""") self.database.conn.commit()
def add_exercise(): exercise_name = input("Name of exercise: ") body_part = input("Body part: ") part_area = input("Area: ") modality = input("Modality: ") db = Database.get_instance() db.add_exercise(exercise_name=exercise_name, body_part=body_part, part_area=part_area, modality=modality)
class FavoritesService: def __init__(self): self.__database = Database() self.__parser = Parser() self.__validations = FavoriteValidations() def insert_favorite(self, product_id: str, customer_id: str): try: LOGGER.debug('Inserting product to customer list') self.__validations.validate_customer_product_id(product_id=product_id, customer_id=customer_id) customer = self.__database.get_customer_by_id(customer_id=customer_id) product = self.__database.get_product_by_id(product_id=product_id) customer = self.__database.push_product_to_favorites(customer=customer, product=product) return self.__parser.parse_customer_favorites(customer=customer) except NotUniqueError: LOGGER.info('Email already used') raise EmailAlreadyUsedException() except ValidationError as exception: LOGGER.debug(traceback.format_exc()) LOGGER.debug('Invalid fields value') raise InvalidFieldsValuesException(validations=exception.to_dict()) except MissingRequiredFieldsException as exception: raise exception except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception def remove_favorite(self, product_id: str, customer_id: str): try: LOGGER.debug('Removing product to customer list') self.__validations.validate_customer_product_id(product_id=product_id, customer_id=customer_id) customer = self.__database.get_customer_by_id(customer_id=customer_id) product = self.__database.get_product_by_id(product_id=product_id) customer = self.__database.pull_product_to_favorites(customer=customer, product=product) return self.__parser.parse_customer_favorites(customer=customer) except NotUniqueError: LOGGER.info('Email already used') raise EmailAlreadyUsedException() except ValidationError as exception: LOGGER.debug(traceback.format_exc()) LOGGER.debug('Invalid fields value') raise InvalidFieldsValuesException(validations=exception.to_dict()) except MissingRequiredFieldsException as exception: raise exception except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception
def __init__(self): self.__database = Database() self.__parser = Parser() self.__validations = FavoriteValidations()
from controller import processor from connections.database import Database from model.logger import log import traceback uid = str(uuid.uuid4()) # # try: # conn = psycopg2.connect("dbname='pt' user='******' host='localhost' password='******'") # except: # print ("ERROR: Unable to connect to the database") if __name__ == "__main__": db = Database.get_instance() while True: # text = input("Enter a phrase you want Sam to send: ") # message = URL+"sendMessage?chat_id=375033117&text="+text # cur = conn.cursor() # # cur.execute("UPDATE webhook.incoming_messages set assigned_to='" + uid + "' where id = (SELECT id FROM webhook.incoming_messages where source='Telegram' and assigned_to is null LIMIT 1)") # # conn.commit() # # cur.execute("SELECT id, message from webhook.incoming_messages where assigned_to='" + uid + "' and processed_on is null LIMIT 1") # # rows = cur.fetchall() # rowcount = cur.rowcount #
def __init__(self): self.dataConnection = DB() self.model: object = Form() self.listObjects: list = []
class FormRepository: def __init__(self): self.dataConnection = DB() self.model: object = Form() self.listObjects: list = [] def create_database(self) -> None: self.dataConnection.start(self.model.create_table()) def get_all(self) -> list: return self.dataConnection.select(self.model, None) def get_by_id(self, id: str) -> list: self.model.__set_id(id) return self.dataConnection.select(self.model, f'where id = {self.model.get_id()}') def create(self, url: str, key: str, value: str) -> str: self.model.create_model(url, key, value) self.dataConnection.insert(self.model) def update(self, id: int, url: str, key: str, value: str) -> None: self.model.create_model(url, key, value) self.model.set_id(id) self.dataConnection.update(self.model) self.model = None def delete(self, id: str) -> None: self.model.set_id(id) self.dataConnection.delete(self.model) def truncate(self) -> None: self.dataConnection.delete(self.model, truncate=True)
def get_exercises_from_muscle_group(muscle_group, number_exercises): db = Database.get_instance() exercises = db.get_exercises_from_muscle_group( muscle_group=muscle_group, number_exercises=number_exercises) return exercises
def __init__(self): self.__database = Database() self.__parser = Parser() self.__validations = CustomerValidations()
class CustomerService: def __init__(self): self.__database = Database() self.__parser = Parser() self.__validations = CustomerValidations() def create_customer(self, data: dict): try: LOGGER.debug('Creating customer service') self.__validations.data(data=data) customer = Customer(**data) customer = self.__database.save(document=customer) return self.__parser.raw_to_json( data=customer.to_mongo().to_dict()) except NotUniqueError: LOGGER.info('Email already used') raise EmailAlreadyUsedException() except ValidationError as exception: LOGGER.debug(traceback.format_exc()) LOGGER.debug('Invalid fields value') raise InvalidFieldsValuesException(validations=exception.to_dict()) except MissingRequiredFieldsException as exception: raise exception except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception def get_customer(self, customer_id: str): try: is_object_id(object_id=customer_id) LOGGER.debug(f'Getting customer {customer_id}') customer = self.__database.get_customer_by_id( customer_id=customer_id) return self.__parser.parse_customer_favorites(customer=customer) except NotFoundException as exception: raise exception except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception def delete_customer(self, customer_id: str): try: is_object_id(object_id=customer_id) LOGGER.debug(f'Deleting customer service {customer_id}') self.__database.delete_customer_by_id(customer_id=customer_id) except NotFoundException as exception: raise exception except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception def update_customer(self, data: dict, customer_id: str): try: is_object_id(object_id=customer_id) self.__validations.data(data=data, is_update=True) LOGGER.debug(f'Updating customer service {customer_id}') customer = self.__database.update_customer_by_id( customer_id=customer_id, data=data) return self.__parser.raw_to_json( data=customer.to_mongo().to_dict()) except NotUniqueError: LOGGER.info('Email already used') raise EmailAlreadyUsedException() except ValueError: LOGGER.debug(traceback.format_exc()) LOGGER.debug('Invalid fields value') raise InvalidFieldsValuesException(validations={'field': ''}) except ValidationError as exception: LOGGER.debug(traceback.format_exc()) LOGGER.debug('Invalid fields value') raise InvalidFieldsValuesException( validations={exception.field_name: ''}) except NotFoundException as exception: raise exception except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception
def __init__(self): self.__database = Database() self.__parser = Parser() self.__validations = ProductValidations()
class ProductService: def __init__(self): self.__database = Database() self.__parser = Parser() self.__validations = ProductValidations() def create_product(self, data: dict): try: LOGGER.debug('Creating product service') self.__validations.product_data(data=data) product = Product(**data) product = self.__database.save(document=product) return self.__parser.raw_to_json(data=product.to_mongo().to_dict()) except ValidationError as exception: LOGGER.debug(traceback.format_exc()) LOGGER.debug('Invalid fields value') raise InvalidFieldsValuesException(validations=exception.to_dict()) except MissingRequiredFieldsException as exception: raise exception except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception def get_product(self, product_id: str): try: is_object_id(object_id=product_id) LOGGER.debug(f'Getting product {product_id}') product = self.__database.get_product_by_id(product_id=product_id) return self.__parser.raw_to_json(data=product.to_mongo().to_dict()) except NotFoundException as exception: raise exception except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception def delete_product(self, product_id: str): try: is_object_id(object_id=product_id) LOGGER.debug(f'Deleting product service {product_id}') self.__database.delete_product_by_id(product_id=product_id) except NotFoundException as exception: raise exception except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception def update_product(self, data: dict, product_id: str): try: is_object_id(object_id=product_id) self.__validations.product_data(data=data, is_update=True) LOGGER.debug(f'Updating product service {product_id}') product = self.__database.update_product_by_id( product_id=product_id, data=data) return self.__parser.raw_to_json(data=product.to_mongo().to_dict()) except ValueError: LOGGER.debug(traceback.format_exc()) LOGGER.debug('Invalid fields value') raise InvalidFieldsValuesException(validations={'field': ''}) except ValidationError as exception: LOGGER.debug(traceback.format_exc()) LOGGER.debug('Invalid fields value') raise InvalidFieldsValuesException( validations={exception.field_name: ''}) except NotFoundException as exception: raise exception except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception def get_products(self, page: str): try: LOGGER.debug('Getting products service') parse_page = self.__parser.page(page=page) products, products_total = self.__database.get_products( page=parse_page) return self.__parser.products(data=list(products.as_pymongo()), total=products_total, page=parse_page) except Exception as exception: LOGGER.debug(traceback.format_exc()) LOGGER.critical(exception) raise exception