Skip to content

Commit

Permalink
formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
XieXiLin2 committed Jan 19, 2024
1 parent a0b4ead commit 6e0b6db
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions nonebot_plugin_cnrail/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ def __init__(self, trains: List[TrainSummary]) -> None:
async def query_train_info(train_code: str, train_date: str) -> Optional[TrainInfo]:
train_code = train_code.upper()

async with httpx.AsyncClient(follow_redirects=True) as client:
resp = await client.get(
CHINA_RAIL_SEARCH_API,
params={
"keyword": train_code,
"date": train_date.replace("-", ""),
},
)
resp.raise_for_status()
async def get_search_data(train_code: str, train_date: str) -> Optional[List]:
async with httpx.AsyncClient(follow_redirects=True) as client:
resp = await client.get(
CHINA_RAIL_SEARCH_API,
params={
"keyword": train_code,
"date": train_date.replace("-", ""),
},
)
resp.raise_for_status()

raw_data = resp.json()["data"]
return resp.json()["data"]

raw_data = await get_search_data(train_code=train_code, train_date=train_date)
if not raw_data:
async with httpx.AsyncClient(
base_url=CNRAIL_DATA_BASE_URL,
Expand All @@ -53,17 +56,7 @@ async def query_train_info(train_code: str, train_date: str) -> Optional[TrainIn

train_code = resp.json()[train_code]

async with httpx.AsyncClient(follow_redirects=True) as client:
resp = await client.get(
CHINA_RAIL_SEARCH_API,
params={
"keyword": train_code,
"date": train_date.replace("-", ""),
},
)
resp.raise_for_status()

raw_data = resp.json()["data"]
raw_data = await get_search_data(train_code=train_code, train_date=train_date)
if not raw_data:
return None

Expand Down

0 comments on commit 6e0b6db

Please sign in to comment.