key 设置48小时时效
This commit is contained in:
@@ -13,8 +13,11 @@ def process_message(message:WxMsg):
|
||||
current_date = datetime.now().strftime('%Y-%m-%d')
|
||||
# 生成Redis key
|
||||
key = f"{message.roomid}:{message.sender}:{current_date}:count"
|
||||
|
||||
# 使用Redis哈希(或字符串)增加发言次数
|
||||
r.hincrby(key, 'count', 1) # 这里使用哈希,但也可以考虑用字符串的INCR操作
|
||||
# 设置时效为48小时
|
||||
r.expire(key,86400*2)
|
||||
# 或者使用字符串:r.incr(key) # 如果只存储一个整数值,字符串类型可能更简单
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ def generate_and_send_ranking(groupId,allContacts: dict):
|
||||
conn = sqlite3.connect('message_stats.db')
|
||||
cursor = conn.cursor()
|
||||
|
||||
yesterday = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d')
|
||||
# 编写SQL查询来获取发言数量前20的用户
|
||||
query = """
|
||||
SELECT group_id,wx_id, COUNT(*) AS speech_count
|
||||
@@ -59,7 +60,7 @@ def generate_and_send_ranking(groupId,allContacts: dict):
|
||||
results = cursor.fetchall()
|
||||
|
||||
# 格式化输出字符串
|
||||
ranking_str = "发言数量前20的用户排名:\n"
|
||||
ranking_str = yesterday + "发言数量前20的用户排名:\n"
|
||||
for rank, (username, speech_count) in enumerate(results, start=1):
|
||||
ranking_str += f"{rank}. {allContacts[username]}: {speech_count} 次发言\n"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user