Skip to content

Commit

Permalink
notify admin on similar enough gifts in list
Browse files Browse the repository at this point in the history
  • Loading branch information
Perceval ARENOU committed Nov 20, 2023
1 parent f44a24f commit 72b204c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/flantier/_commands_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from logging import getLogger

from telegram import (
Bot,
ForceReply,
Update,
)
from telegram.ext import (
Expand Down Expand Up @@ -43,6 +45,18 @@ def is_admin(update: Update, context: CallbackContext) -> bool:
return True


def send_admin_notification(message: str) -> None:
administrator = SettingsManager().settings["telegram"]["administrator"]
Bot(token=SettingsManager().settings["telegram"]["bot_token"]).send_message(
chat_id=administrator,
text=(
"Changer le monde, changer le monde vous êtes bien sympathiques mais faudrait"
" déjà vous levez le matin.\n\n"
+ message
),
)


def open_registrations(update: Update, context: CallbackContext) -> None:
"""Lance la campagne d'inscription. Récupère les résultats de l'année précédente
comme nouvelles conditions de tirage au sort.
Expand Down
15 changes: 12 additions & 3 deletions src/flantier/_santa.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from itertools import zip_longest
from flantier._settings import SettingsManager
from flantier._users import User, UserManager, Wish
from flantier._commands_admin import send_admin_notification

logger = getLogger("flantier")

Expand Down Expand Up @@ -69,7 +70,10 @@ def test_wish_compare() -> None:

for wish in user.wishes:
for w in wishes:
logger.info("diff ratio is %s", SequenceMatcher(a=wish.wish, b=w).ratio())
ratio = SequenceMatcher(a=wish.wish, b=w).ratio()
logger.info("ratio is %s between %s and %s", ratio, wish.wish, w)
if 1 > ratio >= 0.6:
send_admin_notification(f"ratio {ratio}\n{wish.wish}\n{w}")


def compare_gifts(user: User) -> list:
Expand Down Expand Up @@ -103,7 +107,12 @@ def compare_gifts(user: User) -> list:

for wish in user.wishes:
for w in wishes:
logger.info("diff ratio is %s", SequenceMatcher(a=wish, b=w).ratio())
logger.info(
"ratio %s between %s and %s",
SequenceMatcher(a=wish, b=w).ratio(),
wish,
w,
)

# # check if a wish has been removed
# for wish in user.wishes:
Expand Down Expand Up @@ -140,7 +149,7 @@ def update_wishes_list() -> None:
# user.wishes = list(zip(gifts, comments))

wishes = []
for w, c in zip_longest(gifts, comments):
for w, c in zip_longest(gifts, comments, fillvalue=""):
logger.info('adding wish "%s" with comment "%s"', w, c)
wishes.append(Wish(wish=w, comment=c))

Expand Down

0 comments on commit 72b204c

Please sign in to comment.