Skip to content

Commit 96a30f1

Browse files
committed
🔄 refactor: rename functions for contest data fetching
1 parent 6dbde94 commit 96a30f1

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

‎app/crawler/contest.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def request_past_contests(
3939
past_contests.extend(
4040
response.json().get("data", {}).get("pastContests", {}).get("data", [])
4141
)
42-
logger.success("finished")
42+
logger.info(f"{max_page_num=} {len(past_contests)=}")
4343
return past_contests
4444

4545

@@ -57,7 +57,7 @@ async def request_contest_homepage_text():
5757
return req.text
5858

5959

60-
async def save_next_two_contests() -> List[Dict]:
60+
async def request_next_two_contests() -> List[Dict]:
6161
"""
6262
save two coming contests
6363
:return:
@@ -95,7 +95,7 @@ async def save_next_two_contests() -> List[Dict]:
9595
return top_two_contests
9696

9797

98-
async def save_all_past_contests() -> List[Dict]:
98+
async def request_all_past_contests() -> List[Dict]:
9999
"""
100100
Save past contests
101101
:return:
@@ -109,13 +109,15 @@ async def save_all_past_contests() -> List[Dict]:
109109
logger.error("cannot find pageNum")
110110
return []
111111
max_page_num = int(max_page_num_search.groups()[0])
112-
return await request_past_contests(max_page_num)
112+
all_past_contests = await request_past_contests(max_page_num)
113+
return all_past_contests
113114

114115

115-
async def save_recent_contests() -> List[Dict]:
116+
async def request_recent_contests() -> List[Dict]:
116117
"""
117118
Save 10 past contests on the first page
118119
:return:
119120
"""
121+
# 10 contests on the first page, which are enough
120122
ten_past_contests = await request_past_contests(1)
121123
return ten_past_contests

‎app/handler/contest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from beanie.odm.operators.update.general import Set
55
from loguru import logger
66

7-
from app.crawler.contest import save_next_two_contests, save_recent_contests
7+
from app.crawler.contest import request_next_two_contests, request_recent_contests
88
from app.db.models import Contest
99
from app.utils import exception_logger_reraise
1010

@@ -60,8 +60,8 @@ async def save_recent_and_next_two_contests() -> None:
6060
:return:
6161
"""
6262
# Send Http requests to same server, don't do it concurrently
63-
top_two_contests = await save_next_two_contests()
64-
ten_past_contests = await save_recent_contests()
63+
top_two_contests = await request_next_two_contests()
64+
ten_past_contests = await request_recent_contests()
6565
# Save them in database, do it concurrently
6666
await asyncio.gather(
6767
multi_upsert_contests(top_two_contests, past=False),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy