This commit is contained in:
2025-02-05 13:34:19 +08:00
parent 9a2a5009a3
commit 451f885f2d
4 changed files with 18 additions and 20 deletions

View File

@@ -25,6 +25,7 @@ def write_to_db():
# 遍历Redis中所有与昨天日期相关的key并写入数据库
for key in r.keys(f"*:*:{yesterday}:count"):
print('user key{key}')
parts = key.decode('utf-8').split(':')
group_id, wx_id, _date = parts[0], parts[1], parts[2] # _date应该是yesterday但这里为了完整性还是保留
count = int(r.hget(key, 'count')) if isinstance(r.hget(key, 'count'), bytes) else 0 # 处理可能的None或空值情况
@@ -39,7 +40,7 @@ def write_to_db():
def generate_and_send_ranking(groupId,allContacts: dict):
# 连接到SQLite数据库假设数据库文件名为database.db
conn = sqlite3.connect('database.db')
conn = sqlite3.connect('message_stats.db')
cursor = conn.cursor()
# 编写SQL查询来获取发言数量前20的用户