😝修复判断数量的逻辑问题,更新说明文档

This commit is contained in:
柳神 2024-10-29 22:59:36 +08:00
parent a736d8d897
commit 74ffbb98d4
3 changed files with 22 additions and 12 deletions

View File

@ -406,7 +406,7 @@ def marge_errors_from_json_url(errors, marge_json_url):
def deal_with_large_data(result):
"""
处理文章数据保留前200篇及其作者在后续文章中的出现
处理文章数据保留前150篇及其作者在后续文章中的出现
参数
result (dict): 包含统计数据和文章数据的字典
@ -414,17 +414,18 @@ def deal_with_large_data(result):
返回
dict: 处理后的数据只包含需要的文章
"""
result = sort_articles_by_time(result)
article_data = result.get("article_data", [])
# 检查文章数量是否大于 200
if len(article_data) > 200:
# 检查文章数量是否大于 150
if len(article_data) > 150:
print("数据量较大,开始进行处理···")
# 获取前 200 篇文章的作者集合
first_200_authors = {article["author"] for article in article_data[:200]}
# 从第201篇开始过滤只保留前200篇出现过的作者的文章
filtered_articles = article_data[:200] + [
article for article in article_data[200:]
# 从第151篇开始过滤只保留前150篇出现过的作者的文章
filtered_articles = article_data[:150] + [
article for article in article_data[150:]
if article["author"] in first_200_authors
]

View File

@ -11,6 +11,12 @@
## 开发进度
### 2024-10-29
* 完善github数据获取从环境变量中直接获取配置文件仅用于自部署
* 限制文章数量防止因为数量过大导致的api文件加载缓慢仅保留150左右文章([#23](https://github.com/willow-god/Friend-Circle-Lite/pull/23))
* 修改action中写错的github_token拼写
### 2024-10-07
* 添加随机文章刷新按钮
@ -22,13 +28,13 @@
* 美化展示页面UI(@JLinMr),添加背景图片
* 优化作者卡片弹窗动效(@JLinMr)
### 2024-09-22
* 修复 #18 提出的由于rss倒序导致限制抓取错误的问题改为先全部获取后按照时间排序再选择性获取
<details>
<summary>查看更多</summary>
<h3>2024-09-22</h3>
* 修复 #18 提出的由于rss倒序导致限制抓取错误的问题改为先全部获取后按照时间排序再选择性获取
<h3>2024-09-05</h3>
* 更新部署方式将静态文件放到page分支下主分支不放数据文件
@ -426,3 +432,6 @@ python3 run.py
如果遇到任何问题或有建议,请[提交一个 issue](https://github.com/willow-god/Friend-Circle-Lite/issues)。欢迎贡献代码!
## Star增长曲线
[![Star History Chart](https://api.star-history.com/svg?repos=willow-god/Friend-Circle-Lite&type=Timeline)](https://star-history.com/#willow-god/Friend-Circle-Lite&Timeline)

4
run.py
View File

@ -23,9 +23,9 @@ if config["spider_settings"]["enable"]:
result = marge_data_from_json_url(result, marge_json_url + "/all.json")
lost_friends = marge_errors_from_json_url(lost_friends, marge_json_url + "/errors.json")
result = deal_with_large_data(result)
sorted_result = sort_articles_by_time(result)
with open("all.json", "w", encoding="utf-8") as f:
json.dump(sorted_result, f, ensure_ascii=False, indent=2)
json.dump(result, f, ensure_ascii=False, indent=2)
with open("errors.json", "w", encoding="utf-8") as f:
json.dump(lost_friends, f, ensure_ascii=False, indent=2)