diff --git a/docs/README.md b/docs/README.md index c39a2f6a20..ee27b53b1d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1518,7 +1518,11 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 - + + + + + ### 维基百科 diff --git a/router.js b/router.js index 43153e039b..f43193bff5 100644 --- a/router.js +++ b/router.js @@ -384,6 +384,8 @@ router.get('/namoc/specials', require('./routes/namoc/specials')); // 懂球帝 router.get('/dongqiudi/daily', require('./routes/dongqiudi/daily')); router.get('/dongqiudi/result/:team', require('./routes/dongqiudi/result')); +router.get('/dongqiudi/team_news/:team', require('./routes/dongqiudi/team_news')); +router.get('/dongqiudi/player_news/:id', require('./routes/dongqiudi/player_news')); // 维基百科 router.get('/wikipedia/mainland', require('./routes/wikipedia/mainland')); diff --git a/routes/dongqiudi/player_news.js b/routes/dongqiudi/player_news.js new file mode 100644 index 0000000000..cdf24f1dba --- /dev/null +++ b/routes/dongqiudi/player_news.js @@ -0,0 +1,56 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const dayjs = require('dayjs'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const link = `https://www.dongqiudi.com/player/${id}.html`; + const api = `https://www.dongqiudi.com/data/person/archive?person=${id}`; + + const axios_ins = axios.create({ + headers: { + 'X-Requested-With': 'XMLHttpRequest', + Referer: link, + }, + }); + + const response = await axios_ins.get(link); + const $ = cheerio.load(response.data); + const playerName = `${$('h1.name').text()} ${$('span.en_name').text()}`; + + const list = (await axios_ins.get(api)).data.data; + + const out = await Promise.all( + list.map(async (item) => { + const itemUrl = item.web_url; + const res = await axios_ins.get(itemUrl); + const content = cheerio.load(res.data); + + if (itemUrl.includes('/video/')) { + content('div.video').each((i, v) => { + const link = v.attribs.src; + content('div.video').replaceWith(``); + }); + } + + const serverOffset = new Date().getTimezoneOffset() / 60; + const single = { + title: content('h1').text(), + guid: itemUrl, + link: itemUrl, + description: content('#con > div.left > div.detail > div:nth-child(3)').html(), + pubDate: dayjs(content('#con h4 span.time').text()) + .add(-8 - serverOffset, 'hour') + .toISOString(), + author: content('#con h4 span.name').text(), + }; + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `${playerName} - 相关新闻`, + link, + item: out, + }; +}; diff --git a/routes/dongqiudi/team_news.js b/routes/dongqiudi/team_news.js new file mode 100644 index 0000000000..e1ba77a5cf --- /dev/null +++ b/routes/dongqiudi/team_news.js @@ -0,0 +1,56 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const dayjs = require('dayjs'); + +module.exports = async (ctx) => { + const team = ctx.params.team; + const link = `https://www.dongqiudi.com/team/${team}.html`; + const api = `https://www.dongqiudi.com/data/team/archive?team=${team}`; + + const axios_ins = axios.create({ + headers: { + 'X-Requested-With': 'XMLHttpRequest', + Referer: link, + }, + }); + + const response = await axios_ins.get(link); + const $ = cheerio.load(response.data); + const teamName = $('h1.name').text(); + + const list = (await axios_ins.get(api)).data.data; + + const out = await Promise.all( + list.map(async (item) => { + const itemUrl = item.web_url; + const res = await axios_ins.get(itemUrl); + const content = cheerio.load(res.data); + + if (itemUrl.includes('/video/')) { + content('div.video').each((i, v) => { + const link = v.attribs.src; + content('div.video').replaceWith(``); + }); + } + + const serverOffset = new Date().getTimezoneOffset() / 60; + const single = { + title: content('h1').text(), + guid: itemUrl, + link: itemUrl, + description: content('#con > div.left > div.detail > div:nth-child(3)').html(), + pubDate: dayjs(content('#con h4 span.time').text()) + .add(-8 - serverOffset, 'hour') + .toISOString(), + author: content('#con h4 span.name').text(), + }; + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `${teamName} - 相关新闻`, + link, + item: out, + }; +};