更新数据截止日2025.12.25
This commit is contained in:
56
script.py
56
script.py
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from api.lib import DatabaseManager
|
from api.lib import DatabaseManager
|
||||||
from chat_session import ChatSessionManager
|
from chat_session import ChatSessionManager
|
||||||
@@ -18,6 +19,7 @@ def get_token(key, secret):
|
|||||||
at = get_token(apk, aps)
|
at = get_token(apk, aps)
|
||||||
cat = get_token(apk, caps)
|
cat = get_token(apk, caps)
|
||||||
|
|
||||||
|
|
||||||
def get_group_list(users: list):
|
def get_group_list(users: list):
|
||||||
resp = requests.post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/list?access_token=" + at, json={
|
resp = requests.post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/list?access_token=" + at, json={
|
||||||
"status_filter": 0,
|
"status_filter": 0,
|
||||||
@@ -30,6 +32,7 @@ def get_group_list(users:list):
|
|||||||
print(result)
|
print(result)
|
||||||
return result["group_chat_list"]
|
return result["group_chat_list"]
|
||||||
|
|
||||||
|
|
||||||
def get_inner_group_info(gid: str):
|
def get_inner_group_info(gid: str):
|
||||||
resp = requests.post("https://qyapi.weixin.qq.com/cgi-bin/msgaudit/groupchat/get?access_token=" + cat, json={
|
resp = requests.post("https://qyapi.weixin.qq.com/cgi-bin/msgaudit/groupchat/get?access_token=" + cat, json={
|
||||||
"roomid": gid
|
"roomid": gid
|
||||||
@@ -57,6 +60,7 @@ def get_group_info(group_list):
|
|||||||
with open("groupchat.json", "w", encoding="utf-8") as f:
|
with open("groupchat.json", "w", encoding="utf-8") as f:
|
||||||
json.dump(mapping, f, ensure_ascii=False, indent=4)
|
json.dump(mapping, f, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
|
|
||||||
def update_user_group_info():
|
def update_user_group_info():
|
||||||
dm = DatabaseManager('db/data', online_db_uri="zysl-log/wework/chat_msg/db/data.db")
|
dm = DatabaseManager('db/data', online_db_uri="zysl-log/wework/chat_msg/db/data.db")
|
||||||
conn = dm.get_connection()
|
conn = dm.get_connection()
|
||||||
@@ -91,22 +95,56 @@ def update_user_group_info():
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def generate_hourly_intervals(start_time_str):
|
||||||
|
"""
|
||||||
|
生成从开始时间到结束时间之间的每一个小时节点
|
||||||
|
时间格式: "YYYY-MM-DD-HH"
|
||||||
|
"""
|
||||||
|
# 解析时间字符串
|
||||||
|
start_parts = start_time_str.split("-")
|
||||||
|
end_parts = datetime.today().strftime("%Y-%m-%d-%H").split("-")
|
||||||
|
|
||||||
|
# 创建datetime对象
|
||||||
|
start_dt = datetime(int(start_parts[0]), int(start_parts[1]), int(start_parts[2]), int(start_parts[3]))
|
||||||
|
end_dt = datetime(int(end_parts[0]), int(end_parts[1]), int(end_parts[2]), int(end_parts[3]))
|
||||||
|
|
||||||
|
# 计算时间差(小时)
|
||||||
|
time_diff = end_dt - start_dt
|
||||||
|
total_hours = int(time_diff.total_seconds() / 3600)
|
||||||
|
|
||||||
|
# 生成每个小时节点
|
||||||
|
current_dt = start_dt
|
||||||
|
hour_intervals = []
|
||||||
|
|
||||||
|
for i in range(total_hours + 1):
|
||||||
|
hour_str = current_dt.strftime("%Y-%m-%d-%H")
|
||||||
|
hour_intervals.append(hour_str)
|
||||||
|
|
||||||
|
# 移动到下一个小时
|
||||||
|
current_dt += timedelta(hours=1)
|
||||||
|
|
||||||
|
return hour_intervals[1:]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
db_manager = DatabaseManager('db/data', online_db_uri="zysl-log/wework/chat_msg/db/data.db")
|
db_manager = DatabaseManager('db/data', online_db_uri="zysl-log/wework/chat_msg/db/data.db")
|
||||||
# update messages info
|
# update messages info
|
||||||
|
|
||||||
chat_session = ChatSessionManager(db_manager)
|
chat_session = ChatSessionManager(db_manager)
|
||||||
month = 12
|
result = \
|
||||||
day_start = 25
|
db_manager.execute_query("select datetime from 'information' order by datetime desc limit 1", fetch_all=True)[0]
|
||||||
day_end = 26
|
datetime_str = result["datetime"]
|
||||||
for day in range(day_start, day_end):
|
intervals = generate_hourly_intervals(datetime_str)
|
||||||
for hour in range(24):
|
start_year, start_month, start_day, start_hour = intervals[0].split("-")
|
||||||
chat_session.process_chat_session(2025, month, day, hour)
|
end_year, end_month, end_day, end_hour = intervals[-1].split("-")
|
||||||
chat_session.update_qa_data(f"2025-{month}-{day_start:02d} 00:00:00", f"2025-{month}-{day_end:02d} 00:00:00")
|
for interval in intervals:
|
||||||
|
year, month, day, hour = interval.split("-")
|
||||||
|
chat_session.process_chat_session(int(year), int(month), int(day), int(hour))
|
||||||
|
|
||||||
|
chat_session.update_qa_data(f"{start_year}-{start_month}-{start_day} {start_hour}:00:00",
|
||||||
|
f"{end_year}-{end_month}-{end_day} {end_hour}:59:59")
|
||||||
# update user group info
|
# update user group info
|
||||||
|
|
||||||
update_user_group_info()
|
update_user_group_info()
|
||||||
# upload db
|
# upload db
|
||||||
|
|
||||||
db_manager.upload_db()
|
db_manager.upload_db()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user