init commit
This commit is contained in:
25
data/store.py
Normal file
25
data/store.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from utils.io import write_json
|
||||
|
||||
def save_links_snapshot(path, keywords, items, links):
|
||||
"""写入链接快照
|
||||
|
||||
结构:`{'keywords': list, 'items': list, 'total_count': int, 'links': list}`
|
||||
"""
|
||||
write_json(path, {'keywords': list(keywords), 'items': items, 'total_count': len(links), 'links': all_links(links)})
|
||||
return path
|
||||
|
||||
def save_comments_snapshot(path, items):
|
||||
"""写入评论快照:`{'items': items}`"""
|
||||
write_json(path, {'items': items})
|
||||
return path
|
||||
|
||||
def all_links(links):
|
||||
"""将任意可迭代链接转为列表(用于 JSON 序列化)"""
|
||||
return list(links)
|
||||
"""数据快照写入工具
|
||||
|
||||
职责:
|
||||
- 将链接搜索的结果按统一结构写入 JSON
|
||||
- 将评论抓取的结果写入 JSON
|
||||
仅负责序列化,不包含业务逻辑。
|
||||
"""
|
||||
Reference in New Issue
Block a user