def func2(key, attribute): db_session = DBFactory().get_db_session() # query_sql = 'SELECT item_date from items where item_key = :item_key order by item_code desc' # db_session.execute(query_sql, {'item_key': item_key}) query = db_session.query(attribute).filter(DBKey.key_ == key) print(query) result = query.first() print(result[0])
def db_find_min_code(item_key): db_session = DBFactory().get_db_session() query = db_session.query(DBItem.item_code) result = query.order_by(DBItem.item_code.asc()).filter(DBItem.item_key == item_key).limit(1).first() if result is not None: return result.item_code else: return item_key + '-001'
def db_if_code_exist(item_code): db_session = DBFactory().get_db_session() query = db_session.query(func.count('*')) result = query.filter(DBItem.item_code == item_code).first() return result[0]
def db_if_key_exist(key): db_session = DBFactory().get_db_session() query = db_session.query(func.count('*')) result = query.filter(DBKey.key_ == key).first() return result[0]
def db_find_attribute(key, attribute): db_session = DBFactory().get_db_session() query = db_session.query(attribute).filter(DBKey.key_ == key) result = query.first() return result[0]
def db_find_key_total(item_key): db_session = DBFactory().get_db_session() query = db_session.query(func.count('*')) result = query.filter(DBItem.item_key == item_key).first() return result[0]
def db_find_attribute(item_code, attribute): db_session = DBFactory().get_db_session() query = db_session.query(attribute).filter(DBItem.item_code == item_code) logging.info(query) result = query.first() return result[0]
def db_find_max_date(item_key): db_session = DBFactory().get_db_session() query = db_session.query(DBItem.item_date) result = query.order_by(DBItem.item_code.desc()).filter(DBItem.item_key == item_key).limit(1).first() return result.item_date
from Entity.Statistic import Statistic from Entity.Status import Status from Factory.DBFactory import DBFactory from Factory.LogFactory import LogFactory from Service.ConfigService import ConfigService from Service.DBItemService import DBItemService from Service.DBKeyService import DBKeyService from Service.ItemService import ItemService from Service.NetworkService import NetworkService from Service.StatisticsService import StatisticsService from Utility.Utility import Utility ######################################################################################################## warnings.filterwarnings("ignore") ConfigService().init() DBFactory() Statistic() LogFactory().init() retry = int() ######################################################################################################## def search_by_code(item, image, dst_dir): result = Status.ERROR sleep(1) db = DBItemService.db_if_code_exist(item.get_code) try: code = item.get_code item_html = NetworkService.get_search_html(code) soup = BeautifulSoup(item_html.text, "html.parser")