Commit 2541dc3
Changed files (1)
src
danmu
src/danmu/sync.py
@@ -124,7 +124,7 @@ async def save_livechats_to_turso(live_info: dict, data: list[dict], qtype: str)
added.add(f"{date}{time}{x['content']}")
else:
for x in sorted(data, key=lambda x: x.get("timestamp") or 0):
- # time, user, fullname, content, uid, superchat, currency, segmented
+ # time, fullname, content, uid, superchat, currency, segmented
item = {}
if not all([x.get("timestamp"), x.get("authorName")]):
continue
@@ -184,8 +184,8 @@ async def filter_records_in_turso(data: list[dict], date: str, qtype: str) -> li
由于过了凌晨的数据在原始数据库中还是记录为前一天
所以我们应该获取到第二天凌晨8点前的数据 (已下播), 以过滤掉已保存的记录
"""
- # 对于发言, 使用time过滤即可, 对于弹幕, 需要使用time和user
- identifier = "time" if qtype == "发言" else "time,user"
+ # 对于发言, 使用time过滤即可, 对于弹幕, 需要使用time和fullname
+ identifier = "time" if qtype == "发言" else "time,fullname"
tomorrow = datetime.strptime(date, "%Y-%m-%d").astimezone(ZoneInfo(TZ)) + timedelta(days=1)
resp = await turso_exec(
[{"type": "execute", "stmt": {"sql": f'SELECT {identifier} FROM "{qtype}" WHERE time >= "{date} 00:00:00" AND time <= "{tomorrow:%Y-%m-%d} 08:00:00";'}}],
@@ -197,7 +197,7 @@ async def filter_records_in_turso(data: list[dict], date: str, qtype: str) -> li
saved = {"-".join(x) for x in saved} # convert to set to speedup.
log = f"Found {len(saved)} messages in Turso of date {date}"
log += f" Rows read: {glom(resp, 'results.0.response.result.rows_read', default=1)}"
- filtered = [x for x in data if x["time"] not in saved] if qtype == "发言" else [x for x in data if f"{x['time']}-{x['user']}" not in saved]
+ filtered = [x for x in data if x["time"] not in saved] if qtype == "发言" else [x for x in data if f"{x['time']}-{x['fullname']}" not in saved]
logger.info(f"{log}. Remains: {len(filtered)}")
return filtered