def add_to_database_thread(self, lock: threading.Lock) -> None:
     # print(threading.get_ident())
     with lock:
         session = shared_session()
         session.add(self)
         session.commit()
         session.close()
 def update_in_database_thread(self, lock: threading.Lock) -> None:
     with lock:
         session = shared_session()
         session.delete(
             session.query(Item).filter_by(item_id=self.item_id).first())
         session.add(self)
         session.commit()
 def get_from_database(self, lock: threading.Lock = None):
     session = shared_session()
     if lock is not None:
         with lock:
             return session.query(Item).filter_by(
                 item_id=self.item_id).first()
     return session.query(Item).filter_by(item_id=self.item_id).first()
Esempio n. 4
0
def add_all_to_database(list_of_prices: list, lock: multiprocessing.Lock) -> None:
    if list_of_prices:
        with lock:
            session = shared_session()
            session.add_all(list_of_prices)
            session.commit()
            session.close()
Esempio n. 5
0
 def update_in_database(self, lock: multiprocessing.Lock) -> None:
     with lock:
         session = shared_session()
         session.delete(session.query(Price).filter_by(item_id=self.item_id).first())
         session.add(self)
         session.commit()
         session.close()
Esempio n. 6
0
def is_item_id_in_database(item_id: int, session_lock: multiprocessing.Lock) -> bool:
    logger = py_logging.create_logger(
        "is_item_id_in_database", '{}in_database.log'.format(os.path.dirname(os.path.realpath(__file__)) + os.sep))
    with session_lock:
        session = shared_session()
        count = session.query(Item).filter(Item.item_id == item_id).count()
        session.close()
    logger.debug("Number of {} in database: {}".format(item_id, count))
    return bool(count)
 def add_to_database(self, lock: threading.Lock = None) -> None:
     session = shared_session()
     if lock is not None:
         with lock:
             session.add(self)
             session.commit()
     else:
         session.add(self)
         session.commit()
Esempio n. 8
0
def get_singular_ids_in_database(session_lock: multiprocessing.Lock) -> list:
    logger = py_logging.create_logger(
        "get_ids_in_database", '{}in_database.log'.format(os.path.dirname(os.path.realpath(__file__)) + os.sep))
    with session_lock:
        session = shared_session()
        return [x for x in session.query(Item).filter(
                or_(Item.name == "None",
                    Item.type == "None",
                    Item.is_members_only.is_(None),
                    Item.description == "None"))]
 def delete_in_database(self, lock: threading.Lock = None) -> None:
     session = shared_session()
     if lock is not None:
         with lock:
             session.delete(
                 session.query(Item).filter_by(
                     item_id=self.item_id).first())
             session.commit()
     else:
         session.delete(
             session.query(Item).filter_by(item_id=self.item_id).first())
         session.commit()
Esempio n. 10
0
def get_days_for_item(item_id: int, session_lock: multiprocessing.Lock) -> list:
    with session_lock:
        session = shared_session()
        return [x for x in session.query(Price.runescape_time, Price.price)
                .filter(Price.item_id == item_id).distinct()]
Esempio n. 11
0
def get_days_in_database(item_id: int, session_lock: multiprocessing.Lock) -> list:
    logger = py_logging.create_logger(
        "get_ids_in_database", '{}in_database.log'.format(os.path.dirname(os.path.realpath(__file__)) + os.sep))
    with session_lock:
        session = shared_session()
        return [x[0] for x in session.query(Price.runescape_time).filter(Price.item_id == item_id).distinct()]
Esempio n. 12
0
def get_ids_in_database(session_lock: multiprocessing.Lock) -> list:
    logger = py_logging.create_logger(
        "get_ids_in_database", '{}in_database.log'.format(os.path.dirname(os.path.realpath(__file__)) + os.sep))
    with session_lock:
        session = shared_session()
        return [x[0] for x in session.query(Item.item_id).distinct()]
Esempio n. 13
0
 def add_to_database(self, lock: multiprocessing.Lock) -> None:
     with lock:
         session = shared_session()
         session.add(self)
         session.commit()
         session.close()
Esempio n. 14
0
 def get_from_database(self, lock: multiprocessing.Lock):
     with lock:
         session = shared_session()
         return session.query(Price).filter_by(item_id=self.item_id).first()