added function getTitle() and getDate()
This commit is contained in:
parent
ad5ce277e1
commit
4ef41c18d3
42
src/components/chane.py
Normal file
42
src/components/chane.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from difflib import SequenceMatcher
|
||||||
|
from datetime import date
|
||||||
|
from dateutil.parser import parse
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getDate(user_date):
|
||||||
|
#jeżeli w dacie są jakieś liczby, to uznajemy ją za poprawną datę
|
||||||
|
if any(char.isdigit() for char in user_date):
|
||||||
|
return user_date
|
||||||
|
#synonimy słów oznaczające kolejne dni
|
||||||
|
dict_today = ["dzisiaj", "dziś"]
|
||||||
|
dict_tommorow = ['jutro']
|
||||||
|
dict_day_after_tomorrow = ['za dwa dni', 'pojutrze']
|
||||||
|
|
||||||
|
#sprawdzenie, jak bardzo podobne jest słowo, które podał u żytkownik do jednego z przypadków (i bierzemy najbardziej podobne)
|
||||||
|
result_today = max(map(lambda x: SequenceMatcher(a=user_date, b=x).ratio(), dict_today))
|
||||||
|
result_tommorow = max(map(lambda x: SequenceMatcher(a=user_date, b=x).ratio(), dict_tommorow))
|
||||||
|
result_day_after_tomorrow = max(map(lambda x: SequenceMatcher(a=user_date, b=x).ratio(), dict_day_after_tomorrow))
|
||||||
|
|
||||||
|
#zwrócenie wyniku dzisiaj, dzisiaj+1 (jutro), dzisiaj+2 (pojutrze)
|
||||||
|
if result_today > result_tommorow and result_today > result_day_after_tomorrow:
|
||||||
|
return date.today().strftime("%m.%d")
|
||||||
|
elif result_tommorow > result_day_after_tomorrow:
|
||||||
|
return (date.today() + datetime.timedelta(days=1)).strftime("%m.%d")
|
||||||
|
else:
|
||||||
|
return (date.today() + datetime.timedelta(days=2)).strftime("%m.%d")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getTitle(user_title):
|
||||||
|
titles=["Batman", "Na Noże", "Uncharted", "Ambulans", "Minionki", "Fantastyczne Zwierzęta", "To Nie Wypanda",
|
||||||
|
"Inni Ludzie"]
|
||||||
|
number_list = list(map(lambda x: SequenceMatcher(a=user_title, b=x).ratio(), titles))
|
||||||
|
max_value = max(number_list)
|
||||||
|
max_index = number_list.index(max_value)
|
||||||
|
return titles[max_index]
|
||||||
|
|
||||||
|
#def getSeats:
|
||||||
|
#pass
|
Loading…
Reference in New Issue
Block a user