Compare commits
No commits in common. "53a95bfdf26a52222f4173f9d411a2d36c2f4d20" and "cfa59dfb40cb493c4ba728a2b8927a4dce9361a0" have entirely different histories.
53a95bfdf2
...
cfa59dfb40
1
.gitignore
vendored
1
.gitignore
vendored
@ -33,7 +33,6 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
||||
|
||||
.continue/
|
||||
__test__/data/*.json
|
||||
/src/generated/prisma
|
||||
*.db
|
||||
|
||||
@ -91,12 +91,10 @@ export class KaiqiuService {
|
||||
isFinished,
|
||||
isProcessing,
|
||||
location,
|
||||
nums,
|
||||
see,
|
||||
} = await this.getEventInfo(matchId);
|
||||
const event: IEventInfo = {
|
||||
title,
|
||||
info: [`比赛时间:${startDate}`, place, see, nums],
|
||||
info: [`比赛时间:${startDate}`, place],
|
||||
url: eventURL,
|
||||
startDate,
|
||||
matchId,
|
||||
@ -130,21 +128,14 @@ export class KaiqiuService {
|
||||
|
||||
public static async getEventInfo(eventId: string, force?: boolean) {
|
||||
// https://kaiqiuwang.cc/home/space-event-id-175775.html
|
||||
const key = `my-kaiqiuwang:event-info:${eventId}`;
|
||||
const eventURL = `${this.#baseURL}/home/space-event-id-${eventId}.html`;
|
||||
let eventPage = await redis.get(key) ?? '';
|
||||
if (!eventPage || eventPage.includes('连接超时') || force) {
|
||||
eventPage = await fetch(eventURL, { headers: htmlRequestHeaders }).then(res => res.text() ?? '');
|
||||
await redis.setex(key, 60 * 1, eventPage);
|
||||
}
|
||||
const eventPage = await fetch(eventURL, { headers: htmlRequestHeaders }).then(res => res.text() ?? '');
|
||||
const $ = cheerio.load(eventPage);
|
||||
const eventContent = $('.event_content').text().replace(/(\r|\n)/g, ',').split(',').filter(Boolean).join(' ');
|
||||
const { y, M, D, H, m} = /比赛开始:.*?(?<y>\d{4})年(?<M>\d{2})月(?<D>\d{2})日 \w+ (?<H>\d{2}):(?<m>\d{2})/
|
||||
.exec(eventContent)?.groups ?? {};
|
||||
const startDate = y ? `${y}-${M}-${D} ${H}:${m}` : '';
|
||||
const title = $('#mainarea > h2 > a:nth-child(3)').text().trim();
|
||||
const nums = $('#content > div:nth-child(1) > div > div.event_content > ul > li:nth-child(2)').text();
|
||||
const see = /(?<see>\d+)\b/.exec($('#content > div:nth-child(1) > div > div.event_content > ul > li:nth-child(1)').text())?.groups?.see ?? '';
|
||||
const location = $('#content > div:nth-child(1) > div > div.event_content > dl > dd:nth-child(6) > a')
|
||||
.text().split(' ')?.[1]?.trim() ?? '';
|
||||
const startTime = dayjs.tz(startDate, 'Asia/Tokyo');
|
||||
@ -160,8 +151,6 @@ export class KaiqiuService {
|
||||
isProcessing,
|
||||
isFinished,
|
||||
location,
|
||||
nums,
|
||||
see: see ? `${see} 次查看` : '',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user