Skip to content

Commit 2c23539

Browse files
committed
🐞 fix: 优化漫画更新检查功能
优化判断逻辑,不会再因为用户在浏览器查看过导致数据变化而产生多余更新提示
1 parent 6a344c6 commit 2c23539

File tree

2 files changed

+80
-30
lines changed

2 files changed

+80
-30
lines changed

data/comics.json

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,51 @@
33
"message": "请求成功",
44
"results": {
55
"list": [
6+
{
7+
"uuid": 211473,
8+
"name": null,
9+
"b_folder": false,
10+
"folder_id": null,
11+
"last_browse": {
12+
"last_browse_id": "80e0de68-e9f9-11ea-b8bb-00163e0ca5bd",
13+
"last_browse_name": "第42话"
14+
},
15+
"comic": {
16+
"uuid": "331d4826-9b85-11e8-8c80-c8ff287e7c9d",
17+
"b_display": true,
18+
"name": "別當歐尼醬了!",
19+
"path_word": "biedangounijiangle",
20+
"females": [],
21+
"males": [],
22+
"author": [
23+
{
24+
"name": "ねことうふ(猫豆腐)",
25+
"path_word": "ねことうふ(猫豆腐)"
26+
}
27+
],
28+
"theme": [],
29+
"cover": "https://sb.mangafunb.fun/b/biedangounijiangle/cover/1730054905.jpg.328x422.jpg",
30+
"status": 0,
31+
"popular": 7207001,
32+
"datetime_updated": "2024-12-29",
33+
"last_chapter_id": "b6c180d8-c5bd-11ef-9f6d-3f487b7d9a9a",
34+
"last_chapter_name": "第95话",
35+
"browse": {
36+
"comic_uuid": "331d4826-9b85-11e8-8c80-c8ff287e7c9d",
37+
"path_word": "biedangounijiangle",
38+
"chapter_uuid": "80e0de68-e9f9-11ea-b8bb-00163e0ca5bd",
39+
"chapter_name": "第42话"
40+
}
41+
}
42+
},
643
{
744
"uuid": 211467,
845
"name": null,
946
"b_folder": false,
1047
"folder_id": null,
1148
"last_browse": {
12-
"last_browse_id": "7772c25e-c39f-11ef-9e6c-3f487b7d9a9a",
13-
"last_browse_name": "第31話"
49+
"last_browse_id": "7e1ec59e-c39f-11ef-9e6c-3f487b7d9a9a",
50+
"last_browse_name": "第33話"
1451
},
1552
"comic": {
1653
"uuid": "958da828-41fc-11ef-99c6-3f487b7d9a9a",
@@ -32,15 +69,15 @@
3269
"theme": [],
3370
"cover": "https://sp.mangafunb.fun/p/puputongtongqinyinbu/cover/1733321294.jpg.328x422.jpg",
3471
"status": 0,
35-
"popular": 56149,
72+
"popular": 57597,
3673
"datetime_updated": "2024-12-26",
3774
"last_chapter_id": "7e1ec59e-c39f-11ef-9e6c-3f487b7d9a9a",
3875
"last_chapter_name": "第33話",
3976
"browse": {
4077
"comic_uuid": "958da828-41fc-11ef-99c6-3f487b7d9a9a",
4178
"path_word": "puputongtongqinyinbu",
42-
"chapter_uuid": "7772c25e-c39f-11ef-9e6c-3f487b7d9a9a",
43-
"chapter_name": "第31話"
79+
"chapter_uuid": "7e1ec59e-c39f-11ef-9e6c-3f487b7d9a9a",
80+
"chapter_name": "第33話"
4481
}
4582
}
4683
},
@@ -70,51 +107,42 @@
70107
"theme": [],
71108
"cover": "https://hi77-overseas.mangafunb.fun/yiquanchaoren/cover/1651425894.jpg.328x422.jpg",
72109
"status": 0,
73-
"popular": 18939651,
110+
"popular": 18965696,
74111
"datetime_updated": "2024-12-26",
75112
"last_chapter_id": "e719f362-c349-11ef-9e4c-3f487b7d9a9a",
76113
"last_chapter_name": "第256话"
77114
}
78115
},
79116
{
80-
"uuid": 211473,
117+
"uuid": 212309,
81118
"name": null,
82119
"b_folder": false,
83120
"folder_id": null,
84-
"last_browse": {
85-
"last_browse_id": "0273bdcc-b06d-11ef-9190-3f487b7d9a9a",
86-
"last_browse_name": "第94话"
87-
},
121+
"last_browse": null,
88122
"comic": {
89-
"uuid": "331d4826-9b85-11e8-8c80-c8ff287e7c9d",
123+
"uuid": "259e688c-f526-11e8-b542-00163e0ca5bd",
90124
"b_display": true,
91-
"name": "別當歐尼醬了!",
92-
"path_word": "biedangounijiangle",
125+
"name": "電鋸人",
126+
"path_word": "dianjuren",
93127
"females": [],
94128
"males": [],
95129
"author": [
96130
{
97-
"name": "ねことうふ(猫豆腐)",
98-
"path_word": "ねことうふ(猫豆腐)"
131+
"name": "藤本タツキ",
132+
"path_word": "藤本タツキ"
99133
}
100134
],
101135
"theme": [],
102-
"cover": "https://sb.mangafunb.fun/b/biedangounijiangle/cover/1730054905.jpg.328x422.jpg",
136+
"cover": "https://hi77-overseas.mangafunb.fun/dianjuren/cover/1689304034.jpg.328x422.jpg",
103137
"status": 0,
104-
"popular": 7170366,
105-
"datetime_updated": "2024-12-02",
106-
"last_chapter_id": "0273bdcc-b06d-11ef-9190-3f487b7d9a9a",
107-
"last_chapter_name": "第94话",
108-
"browse": {
109-
"comic_uuid": "331d4826-9b85-11e8-8c80-c8ff287e7c9d",
110-
"path_word": "biedangounijiangle",
111-
"chapter_uuid": "0273bdcc-b06d-11ef-9190-3f487b7d9a9a",
112-
"chapter_name": "第94话"
113-
}
138+
"popular": 45905726,
139+
"datetime_updated": "2024-12-19",
140+
"last_chapter_id": "b48111ea-bda6-11ef-9aed-3f487b7d9a9a",
141+
"last_chapter_name": "第187话"
114142
}
115143
}
116144
],
117-
"total": 3,
145+
"total": 4,
118146
"limit": 20,
119147
"offset": 0
120148
}

utils/run.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
from utils.send_email import send_email
44
from utils.api_request import fetch_comics
55

6+
def check_for_updates(response, comics_data):
7+
response_comics = {comic['comic']['uuid']: comic for comic in response['results']['list']}
8+
comics_data_comics = {comic['comic']['uuid']: comic for comic in comics_data['results']['list']}
9+
10+
for uuid, comic in response_comics.items():
11+
last_chapter_id = comic['comic']['last_chapter_id']
12+
fetch_last = comic['comic']['last_chapter_name']
13+
comic_name = comic['comic']['name'][:10]
14+
print(f"{comic_name}\t 拉取最新: {fetch_last}")
15+
16+
if uuid in comics_data_comics:
17+
old_last_chapter_id = comics_data_comics[uuid]['comic']['last_chapter_id']
18+
local_last = comics_data_comics[uuid]['comic']['last_chapter_name']
19+
old_comic_name = comics_data_comics[uuid]['comic']['name'][:10]
20+
print(f"{old_comic_name}\t 本地最新: {local_last}")
21+
22+
if last_chapter_id != old_last_chapter_id:
23+
return True
24+
return False
25+
626
def run(username, password, salt, vars,from_email, to_email, server,token):
727
try:
828
os.chdir('data')
@@ -14,9 +34,11 @@ def run(username, password, salt, vars,from_email, to_email, server,token):
1434
try:
1535
with open(comics, 'r', encoding='utf-8') as file:
1636
comics_data = json.load(file)
17-
# 比较response内容与comics.json内容
18-
if response == comics_data:
37+
# 检查是否有更新
38+
if not check_for_updates(response, comics_data):
1939
print("无更新😢")
40+
with open(comics, 'w', encoding='utf-8') as file:
41+
json.dump(response, file, ensure_ascii=False, indent=4)
2042
return
2143
except (FileNotFoundError, json.JSONDecodeError):
2244
# 更新comics.json文件内容

0 commit comments

Comments
 (0)