def get_expression_by_operator(field, value: str, operator=None): if operator is None or operator == "equal": return fn.LOWER(field) == value.lower() elif operator == "not" or operator == "not_equal": return fn.LOWER(field) != value.lower() elif operator == "like": return fn.LOWER(field) % get_like_query(value) elif operator == "not_like": return ~(fn.LOWER(field) % get_like_query(value)) return None
def book_search(term): """ Searches the store for books whose author or title contain a search term. Case insensitive. Makes partial matches, so a search for 'row' will match a book with author='JK Rowling' and a book with title='Rowing For Dummies' :param term the search term :returns a list of books with author or title that match the search term. The list will be empty if there are no matches. """ query = Book.select().where((fn.LOWER(Book.title).contains(term.lower())) | (fn.LOWER(Book.author).contains(term.lower()))) return list(query)
def get_organization_by_name(self, name): DbmonitorOrganizacao.bind(self.dbmonitor_database) name = name.lower() org = DbmonitorOrganizacao.get_or_none( fn.LOWER(DbmonitorOrganizacao.nome) == name) if not org: msg = "Organization {} not found.".format(name) logging.error(msg) raise Exception(msg) return org.id
def get_cloud_by_name(self, name): DbmonitorCloud.bind(self.dbmonitor_database) name = name.lower() cloud = DbmonitorCloud.get_or_none( fn.LOWER(DbmonitorCloud.nome) == name) if not cloud: msg = "Cloud {} not found.".format(name) logging.error(msg) raise Exception(msg) return cloud.id
def add_tag(bot, update): user = TGUser.get(handle=update.message.from_user.username) update.message.reply_text( "Updating tags of all messages, this may take a minute or two....") import ipdb ipdb.set_trace() tag = Tag.create(tag=update.message.text.split()[1]) for message in Message.select().where( sqlfn.LOWER(Message.content).contains(tag.tag.lower())): MessageToTags.create(message=message, tag=tag) TGUserToTag.create( user=user, tag=tag, ) update.message.reply_text("Done!")
async def media(ctx, nome_pokemon): if not nome_pokemon: return try: pokemon = Pokemon.select().where( fn.LOWER(Pokemon.nome) == nome_pokemon.lower()).get() except Pokemon.DoesNotExist: await ctx.send( f'Não foi encontrado um pokemon com o nome: {nome_pokemon}') return dados = CalculadorMediaPokemon().calcula_media(pokemon) if dados: msg_media_balls = f'A média para {pokemon.nome} é:\n{dados}' else: msg_media_balls = f'Pokemon sem valor cadastrado, por favor use o comando !valor_na_bola NOME_DO_POKEMON VALOR' await ctx.send(msg_media_balls)
async def valor_na_bola(ctx, nome_pokemon, novo_valor): try: pokemon = Pokemon.select().where( fn.LOWER(Pokemon.nome) == nome_pokemon.lower()).get() except Pokemon.DoesNotExist: await ctx.send( f'Não foi encontrado um pokemon com o nome: {nome_pokemon}') return try: pokemon.preco = int(novo_valor) except ValueError: await ctx.send( f'Envie o valor sem casas decimais ou divisores de milhar') return pokemon.save() await ctx.send( f'O preço para o pokemon {pokemon.nome} foi atualizado para: {novo_valor}' )
async def get_member_by_naive_username(self, username, include_clan=True): username = username.lower() if include_clan: query = Member.select(Member, ClanMember, Clan).join(ClanMember).join(Clan) else: query = Member.select(Member) query = query.where((fn.LOWER(Member.bungie_username) == username) | (fn.LOWER(Member.xbox_username) == username) | (fn.LOWER(Member.psn_username) == username) | (fn.LOWER(Member.blizzard_username) == username) | (fn.LOWER(Member.steam_username) == username) | (fn.LOWER(Member.stadia_username) == username)) return await self.get(query)
async def get_member_by_platform_username(self, username, platform_id): # pylint: disable=assignment-from-no-return query = Member.select() username = username.lower() if platform_id == constants.PLATFORM_BUNGIE: query = query.where(fn.LOWER(Member.bungie_username) == username) elif platform_id == constants.PLATFORM_PSN: query = query.where(fn.LOWER(Member.psn_username) == username) elif platform_id == constants.PLATFORM_XBOX: query = query.where(fn.LOWER(Member.xbox_username) == username) elif platform_id == constants.PLATFORM_BLIZZARD: query = query.where(fn.LOWER(Member.blizzard_username) == username) elif platform_id == constants.PLATFORM_STEAM: query = query.where(fn.LOWER(Member.steam_username) == username) elif platform_id == constants.PLATFORM_STADIA: query = query.where(fn.LOWER(Member.stadia_username) == username) return await self.get(query)
def artist_art_search(term): query = Artwork.select().where( ( fn.LOWER(Artwork.artist).contains(term.lower() ) ) ) return list(query)
def search_artist(term): query = Artist.select().where((fn.LOWER(Artist.artist_name).contains(term.lower()))) return list(query)