Esempio n. 1
0
def add_player(body: AcceptCreate):
    blizzard_id = BlizzardUsersUtils.id__safe(body.token)
    db = blizzard_db()
    qs = DatabaseUtils.core_query(db.query(StaticIndexModel)) \
        .filter(StaticIndexModel.owner_blizzard_id == blizzard_id)

    if qs.count() < 1:
        raise HTTPException(503, 'You cant accept player to not your static')

    q = DatabaseUtils.core_query(db.query(StaticMemberModel)) \
        .filter(StaticMemberModel.id == body.member_id)
    if q.count() < 1:
        raise HTTPException(404, 'You have not got this player')
    q.update({'request_state': 2})
    db.commit()
    return True
Esempio n. 2
0
 def list(db: Session):
     """
     Returns all variables
     :param db:
     :return:
     """
     return DatabaseUtils.core_query(db.query(DataModel)).all()
Esempio n. 3
0
 def get_categories():
     """
     Returns the categories
     :return:
     """
     db = blizzard_db()
     return DatabaseUtils.core_query(db.query(PostCategoryModel)).all()
Esempio n. 4
0
def get_full_user(blizzard_id: int, token: str):
    BlizzardUsersUtils.id__safe(token)
    WAccountUtils.eval_token(token)
    db = blizzard_db()
    return DatabaseUtils.core_query(
        db.query(WAccountModel).filter(
            WAccountModel.user_id == blizzard_id)).all()
 def check(db: Session, user_id: int):
     q = DatabaseUtils.core_query(
         db.query(UserModel).filter(UserModel.id == user_id))
     if q.count() > 0:
         return True
     raise HTTPException(
         status_code=404,
         detail=f"User with user_id [{user_id}] is undefined!")
Esempio n. 6
0
 def get(blizzard_id):
     """
     Returns the blizzard user by blizzard_id
     :param blizzard_id:
     :return:
     """
     db = blizzard_db()
     return DatabaseUtils.core_query(
         db.query(BlizzardUserModel).filter(
             BlizzardUserModel.blizzard_id == blizzard_id)).first()
Esempio n. 7
0
 def get(db: Session, token: str) -> UserAuth:
     """
     Returns the token
     :param db:
     :param token:
     :return:
     """
     db_obj = DatabaseUtils.core_query(db.query(UserAuthModel).filter(UserAuthModel.token == token)).first()
     if db_obj is None:
         raise HTTPException(status_code=201, detail="User's token is undefined!")
     return db_obj
Esempio n. 8
0
 def update_characters_mythic():
     data = DatabaseUtils.core_query(
         blizzard_db().query(CharacterModel)).all()
     logger.info("Starting update characters mythic...")
     logger.info(f"Total count: {len(data)}")
     bar = Bar('Characters mythic updating', max=len(data), fill='█')
     for member in data:
         name = member.name
         MythicUpdater.update_mythic_character(name)
         bar.next()
     print("")
 def get(db: Session, user_id: int, show_removed=False):
     """
     Returns the user by id
     :param show_removed:
     :param db:
     :param user_id:
     :return:
     """
     return DatabaseUtils.core_query(
         db.query(UserModel).filter(UserModel.id == user_id),
         show_removed).first()
Esempio n. 10
0
    def update_characters_images(path=default_characters_images_path):
        """
        Downloads the characters images

        Characters are getting from the database
        :param path:
        :return:
        """
        MediaDownloader.download_characters_images(
            DatabaseUtils.core_query(
                blizzard_db().query(CharacterModel)).all(), path)
Esempio n. 11
0
 def get(db: Session, group_id: int, show_removed=False):
     """
     Returns the user group by id
     :param db:
     :param group_id:
     :param show_removed:
     :return:
     """
     return DatabaseUtils.core_query(
         db.query(UserGroupModel),
         show_removed).filter(UserGroupModel.id == group_id).first()
Esempio n. 12
0
    def by_login(db: Session, login: str, show_removed=False) -> UserModel:
        """
        Returns the user by login

        :param show_removed:
        :param db:
        :param login:
        :return:
        """
        return DatabaseUtils.core_query(
            db.query(UserModel).filter(UserModel.login == login),
            show_removed).first()
 def get(db: Session, user_id: int, field: str, show_removed=False):
     """
     Returns the user meta value
     :param show_removed:
     :param db:
     :param user_id:
     :param field:
     :return:
     """
     return DatabaseUtils.core_query(
         db.query(UserMetaModel).filter(
             UserMetaModel.user_id == user_id).filter(
                 UserMetaModel.field == field), show_removed).first()
Esempio n. 14
0
def add_player(body: StaticMemberCreate):
    blizzard_id = BlizzardUsersUtils.id__safe(body.token)
    db = blizzard_db()
    q = DatabaseUtils.core_query(
        db.query(WAccountModel).filter(
            WAccountModel.user_id == blizzard_id).filter(
                WAccountModel.wow_id == body.wow_id))
    if q.count() < 1:
        raise HTTPException(404, 'You have not got this player')
    return StaticUtils.add_player(static_id=body.static_id,
                                  wow_id=body.wow_id,
                                  role_id=body.role_id,
                                  comment=body.request_comment,
                                  blizzard_id=blizzard_id)
Esempio n. 15
0
 def get(db: Session, field: str):
     """
     Returns the field's value or raises the error
     :param db:
     :param field:
     :return:
     """
     value = DatabaseUtils.core_query(
         db.query(DataModel).filter(DataModel.field == field),
         show_removed=False).first()
     if not value:
         raise HTTPException(status_code=404,
                             detail=f"Stored value [{field}] is undefined!")
     return value
Esempio n. 16
0
 def fix_missed(blizzard_characters: List):
     db = blizzard_db()
     q = DatabaseUtils.core_query(db.query(CharacterModel)).all()
     for character in q:
         found = False
         for b_ch in blizzard_characters:
             if b_ch['character']['name'] == character.name:
                 found = True
         if not found:
             logger.warn(character.name + " escape guild")
             db.query(CharacterModel).filter(
                 CharacterModel.wow_id == character.wow_id).update(
                     {'state': 0})
             db.commit()
Esempio n. 17
0
 def set(db: Session, field: str, value: str):
     """
     Sets the  value
     :param db:
     :param field:
     :param value:
     :return:
     """
     db_meta = DatabaseUtils.core_query(
         db.query(DataModel).filter(DataModel.field == field))
     if db_meta.count() > 0:
         db_meta.update({"value": value})
         db.commit()
         return db_meta.first()
     return DatabaseUtils.insert(db,
                                 db_item=DataModel(field=field,
                                                   value=value))
Esempio n. 18
0
    def add(
            blizzard_id: int,
            wow_id: int,
            name: str,
            realm_id: int,
            realm_title: str,
            level: int,
            faction: str
    ):
        """
        Adds the character
        :param realm_title:
        :param blizzard_id:
        :param wow_id:
        :param name:
        :param realm_id:
        :param level:
        :param faction:
        :return:
        """
        db = blizzard_db()
        q = DatabaseUtils.core_query(db.query(WAccountModel)) \
            .filter(WAccountModel.user_id == blizzard_id) \
            .filter(WAccountModel.wow_id == wow_id)

        if q.count() > 0:
            logger.info(f'Updates: {name}')
            q.update({
                'name': name,
                'realm_id': realm_id,
                'realm_title': realm_title,
                'level': level,
                'faction': faction,
            })
        else:
            logger.info(f'Creates: {name}')
            db.add(WAccountModel(
                user_id=blizzard_id,
                wow_id=wow_id,
                name=name,
                realm_id=realm_id,
                realm_title=realm_title,
                level=level,
                faction=faction
            ))
        db.commit()
 def set(db: Session, user_id: int, field: str, value: str):
     UserActions.check(db, user_id)
     """
     Sets the meta value
     :param db:
     :param user_id:
     :param field:
     :param value:
     :return:
     """
     db_meta = DatabaseUtils.core_query(
         db.query(UserMetaModel).filter(
             UserMetaModel.user_id == user_id).filter(
                 UserMetaModel.field == field))
     if db_meta.count() > 0:
         db_meta.update({"value": value})
         db.commit()
         return db_meta.first()
     return DatabaseUtils.insert(db,
                                 db_item=UserMetaModel(user_id=user_id,
                                                       field=field,
                                                       value=value))
Esempio n. 20
0
 def update():
     db = blizzard_db()
     players = DatabaseUtils.core_query(db.query(CharacterModel)).all()
     for player in players:
         PlayersActivityUpdater.update_player(player.name)
Esempio n. 21
0
 def get(blizzard_id: int):
     db = blizzard_db()
     return DatabaseUtils.core_query(
         db.query(BlizzardUserModel.blizzard_id == blizzard_id)).first()
Esempio n. 22
0
def get_static_list():
    db = blizzard_db()
    return DatabaseUtils.core_query(db.query(StaticIndexModel)).all()