1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

fixed warning in /cerca

This commit is contained in:
Fabio De Simone 2019-01-29 14:48:53 +01:00
parent 5bdacf9496
commit 0d184ea859

View file

@ -4,6 +4,7 @@ import typing
import db import db
import errors import errors
import stagismo import stagismo
from sqlalchemy.sql import text
# python-telegram-bot has a different name # python-telegram-bot has a different name
# noinspection PyPackageRequirements # noinspection PyPackageRequirements
from telegram import Bot, Update, InlineKeyboardMarkup, InlineKeyboardButton from telegram import Bot, Update, InlineKeyboardMarkup, InlineKeyboardButton
@ -305,7 +306,7 @@ def cmd_cerca(bot: Bot, update: Update):
bot.send_message(update.message.chat.id, s(strings.DIARIO_SEARCH.ERRORS.INVALID_SYNTAX)) bot.send_message(update.message.chat.id, s(strings.DIARIO_SEARCH.ERRORS.INVALID_SYNTAX))
return return
queryText = queryText.replace('%', '\\%').replace('_', '\\_') queryText = queryText.replace('%', '\\%').replace('_', '\\_')
entries = session.query(db.Diario).filter(f"text ~* '(?:[^\w\d]+{queryText}[^\w\d]+|^{queryText}[^\w\d]+|^{queryText}$|[^\w\d]+{queryText}$)'").order_by(db.Diario.id).all() entries = session.query(db.Diario).filter(text(f"text ~* '(?:[^\w\d]+{queryText}[^\w\d]+|^{queryText}[^\w\d]+|^{queryText}$|[^\w\d]+{queryText}$)'")).order_by(db.Diario.id).all()
msg = f"Risultati della ricerca di {queryText}:\n" msg = f"Risultati della ricerca di {queryText}:\n"
for entry in entries[:5]: for entry in entries[:5]:
msg += f'<a href="https://ryg.steffo.eu/diario#entry-{entry.id}">#{entry.id}</a> di {entry.author or "Anonimo"}\n{entry.text}\n\n' msg += f'<a href="https://ryg.steffo.eu/diario#entry-{entry.id}">#{entry.id}</a> di {entry.author or "Anonimo"}\n{entry.text}\n\n'