Compare commits

..

No commits in common. "53a95bfdf26a52222f4173f9d411a2d36c2f4d20" and "cfa59dfb40cb493c4ba728a2b8927a4dce9361a0" have entirely different histories.

2 changed files with 2 additions and 14 deletions

1
.gitignore vendored
View File

@ -33,7 +33,6 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# Finder (MacOS) folder config # Finder (MacOS) folder config
.DS_Store .DS_Store
.continue/
__test__/data/*.json __test__/data/*.json
/src/generated/prisma /src/generated/prisma
*.db *.db

View File

@ -91,12 +91,10 @@ export class KaiqiuService {
isFinished, isFinished,
isProcessing, isProcessing,
location, location,
nums,
see,
} = await this.getEventInfo(matchId); } = await this.getEventInfo(matchId);
const event: IEventInfo = { const event: IEventInfo = {
title, title,
info: [`比赛时间:${startDate}`, place, see, nums], info: [`比赛时间:${startDate}`, place],
url: eventURL, url: eventURL,
startDate, startDate,
matchId, matchId,
@ -130,21 +128,14 @@ export class KaiqiuService {
public static async getEventInfo(eventId: string, force?: boolean) { public static async getEventInfo(eventId: string, force?: boolean) {
// https://kaiqiuwang.cc/home/space-event-id-175775.html // 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`; const eventURL = `${this.#baseURL}/home/space-event-id-${eventId}.html`;
let eventPage = await redis.get(key) ?? ''; const eventPage = await fetch(eventURL, { headers: htmlRequestHeaders }).then(res => res.text() ?? '');
if (!eventPage || eventPage.includes('连接超时') || force) {
eventPage = await fetch(eventURL, { headers: htmlRequestHeaders }).then(res => res.text() ?? '');
await redis.setex(key, 60 * 1, eventPage);
}
const $ = cheerio.load(eventPage); const $ = cheerio.load(eventPage);
const eventContent = $('.event_content').text().replace(/(\r|\n)/g, ',').split(',').filter(Boolean).join(' '); 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})/ 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 ?? {}; .exec(eventContent)?.groups ?? {};
const startDate = y ? `${y}-${M}-${D} ${H}:${m}` : ''; const startDate = y ? `${y}-${M}-${D} ${H}:${m}` : '';
const title = $('#mainarea > h2 > a:nth-child(3)').text().trim(); 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') const location = $('#content > div:nth-child(1) > div > div.event_content > dl > dd:nth-child(6) > a')
.text().split(' ')?.[1]?.trim() ?? ''; .text().split(' ')?.[1]?.trim() ?? '';
const startTime = dayjs.tz(startDate, 'Asia/Tokyo'); const startTime = dayjs.tz(startDate, 'Asia/Tokyo');
@ -160,8 +151,6 @@ export class KaiqiuService {
isProcessing, isProcessing,
isFinished, isFinished,
location, location,
nums,
see: see ? `${see} 次查看` : '',
} }
} }