From e5af152d1438ae5fd8b5983a7983969b9eadea90 Mon Sep 17 00:00:00 2001 From: ZaneYork Date: Thu, 12 Sep 2024 10:39:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dao.py | 4 ++-- src/dinner.py | 1 + src/utils.py | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dao.py b/src/dao.py index 466f95e..4f51364 100644 --- a/src/dao.py +++ b/src/dao.py @@ -107,7 +107,7 @@ def fetch_all_menu() -> Generator[tuple[str, str, str], None, None]: db.close() -def fetch_roll_result() -> str|None: +def fetch_roll_result() -> str | None: """ 获取N天前的抽签结果 :return: 抽签结果 @@ -118,7 +118,7 @@ def fetch_roll_result() -> str|None: cursor = db.cursor() try: cursor.execute("select value from roll_result where datestr=?", - (datestr, )) + (datestr,)) row = cursor.fetchone() if row is not None: return row[0] diff --git a/src/dinner.py b/src/dinner.py index b81ce4f..0d8adac 100644 --- a/src/dinner.py +++ b/src/dinner.py @@ -55,6 +55,7 @@ def vote_reduce(summary: dict[str, float], limit: int = 2) -> tuple[dict[str, fl """ 按规则对投票结果进行修饰 :param summary: 投票汇总结果 + :param limit: 降低最近N次点餐结果概率 :return: 投票汇总结果 """ last_results = list(fetch_roll_result_list(-1, limit)) diff --git a/src/utils.py b/src/utils.py index 0b5aca5..6d47a93 100644 --- a/src/utils.py +++ b/src/utils.py @@ -3,10 +3,10 @@ from configparser import ConfigParser from flask import request - config = ConfigParser() config.read('./config.ini') + def is_mobile_request(user_agent: str) -> bool: """ 判断是否是移动端 @@ -16,6 +16,7 @@ def is_mobile_request(user_agent: str) -> bool: ua_expression = config.get('Settings', 'UA_EXPRESSION') return bool(eval(ua_expression, {"user_agent": user_agent, "re": re})) + def get_user() -> str: """ 根据访问IP决定用户ID