fix(route): dongqiudi team_news (#10796)
* fix(route): dongqiudi team_news * fix: category if secondary_category is null
This commit is contained in:
parent
8e6d3adae4
commit
4e94f0e1a8
|
|
@ -1,47 +0,0 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await got.get('https://www.dongqiudi.com/special/48');
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const host = 'https://www.dongqiudi.com';
|
||||
|
||||
const list = $('.detail.special ul li h3')
|
||||
.slice(0, 5)
|
||||
.get()
|
||||
.filter((e) => cheerio.load(e).text().length > 3);
|
||||
|
||||
const proList = [];
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map((item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const title = $('a').text();
|
||||
const itemUrl = host + $('a').attr('href');
|
||||
|
||||
return ctx.cache.tryGet(itemUrl, () => {
|
||||
const single = {
|
||||
title,
|
||||
link: itemUrl,
|
||||
};
|
||||
|
||||
const es = got.get(itemUrl);
|
||||
proList.push(es);
|
||||
return single;
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
const responses = await got.all(proList);
|
||||
for (let i = 0; i < proList.length; i++) {
|
||||
utils.ProcessFeedType2(out[i], responses[i].data);
|
||||
}
|
||||
ctx.state.data = {
|
||||
title: '懂球帝早报',
|
||||
link: 'http://www.dongqiudi.com/special/48',
|
||||
item: out.filter((e) => e.description !== undefined),
|
||||
};
|
||||
};
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const link = `https://www.dongqiudi.com/player/${id}.html`;
|
||||
const playerId = ctx.params.id;
|
||||
|
||||
await utils.ProcessFeed(ctx, link, 'player');
|
||||
await utils.ProcessFeed(ctx, 'player', playerId);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ module.exports = async (ctx) => {
|
|||
const team = ctx.params.team;
|
||||
const link = `https://www.dongqiudi.com/team/${team}.html`;
|
||||
|
||||
const response = await got.get(link);
|
||||
const response = await got(link);
|
||||
const dom = new JSDOM(response.data, {
|
||||
runScripts: 'dangerously',
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/daily', require('./daily'));
|
||||
router.redirect('/daily', '/dongqiudi/special/48');
|
||||
router.get('/player_news/:id', require('./player_news'));
|
||||
router.get('/result/:team', require('./result'));
|
||||
router.get('/special/:id', require('./special'));
|
||||
|
|
|
|||
|
|
@ -4,44 +4,38 @@ const utils = require('./utils');
|
|||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const response = await got.get(`https://www.dongqiudi.com/special/${id}`);
|
||||
const response = await got(`https://www.dongqiudi.com/special/${id}`);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const host = 'https://www.dongqiudi.com';
|
||||
|
||||
const list = $('.detail.special ul li h3').slice(0, 5).get();
|
||||
|
||||
const proList = [];
|
||||
const list = $('.detail.special ul li h3')
|
||||
.slice(0, ctx.query.limit ? Number(ctx.query.limit) : 5)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('a').text(),
|
||||
link: host + item.find('a').attr('href'),
|
||||
};
|
||||
});
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const title = $('a').text();
|
||||
const itemUrl = host + $('a').attr('href');
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
utils.ProcessFeedType2(item, response);
|
||||
|
||||
const single = {
|
||||
title,
|
||||
link: itemUrl,
|
||||
};
|
||||
|
||||
const es = got.get(itemUrl);
|
||||
proList.push(es);
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const responses = await got.all(proList);
|
||||
for (let i = 0; i < proList.length; i++) {
|
||||
utils.ProcessFeedType2(out[i], responses[i].data);
|
||||
}
|
||||
ctx.state.data = {
|
||||
title: `懂球帝专题-${id}`,
|
||||
title: `懂球帝专题-${$('.detail.special h1').text()}`,
|
||||
description: $('.detail.special h4').text(),
|
||||
link: `https://www.dongqiudi.com/special/${id}`,
|
||||
item: out.filter((e) => e !== undefined),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const team = ctx.params.team;
|
||||
const link = `https://www.dongqiudi.com/team/${team}.html`;
|
||||
const teamId = ctx.params.team;
|
||||
|
||||
await utils.ProcessFeed(ctx, link, 'team');
|
||||
await utils.ProcessFeed(ctx, 'team', teamId);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,39 +1,33 @@
|
|||
const got = require('@/utils/got');
|
||||
const utils = require('./utils');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id ?? 1;
|
||||
const response = await got(`https://api.dongqiudi.com/app/tabs/iphone/${id}.json?mark=gif&version=576`);
|
||||
const data = response.data.articles;
|
||||
const label = response.data.label;
|
||||
const { data } = await got(`https://api.dongqiudi.com/app/tabs/web/${id}.json`);
|
||||
const articles = data.articles;
|
||||
const label = data.label;
|
||||
|
||||
const proList = [];
|
||||
const list = articles.map((item) => ({
|
||||
title: item.title,
|
||||
link: `https://www.dongqiudi.com/articles/${item.id}.html`,
|
||||
category: [item.category, ...(item.secondary_category ? item.secondary_category : [])],
|
||||
pubDate: parseDate(item.show_time),
|
||||
}));
|
||||
|
||||
const out = await Promise.all(
|
||||
data.map((item) => {
|
||||
const title = item.title;
|
||||
const itemUrl = `https://www.dongqiudi.com/news/${item.id}.html`;
|
||||
|
||||
return ctx.cache.tryGet(itemUrl, () => {
|
||||
const single = {
|
||||
title,
|
||||
link: itemUrl,
|
||||
};
|
||||
|
||||
const es = got(itemUrl);
|
||||
proList.push(es);
|
||||
return single;
|
||||
});
|
||||
})
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
utils.ProcessFeedType2(item, response);
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const responses = await got.all(proList);
|
||||
for (let i = 0; i < proList.length; i++) {
|
||||
utils.ProcessFeedType2(out[i], responses[i].data);
|
||||
}
|
||||
ctx.state.data = {
|
||||
title: `懂球帝 - ${label}`,
|
||||
link: 'http://dongqiudi.com/news',
|
||||
link: `https://www.dongqiudi.com/articlesList/${id}`,
|
||||
item: out.filter((e) => e !== undefined),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -61,57 +61,57 @@ const ProcessImg = (content) => {
|
|||
});
|
||||
};
|
||||
|
||||
const ProcessFeed = async (ctx, link, type) => {
|
||||
const got_ins = got.extend({
|
||||
headers: {
|
||||
Referer: link,
|
||||
},
|
||||
});
|
||||
|
||||
const response = await got_ins.get(link);
|
||||
const ProcessFeed = async (ctx, type, id) => {
|
||||
const link = `https://www.dongqiudi.com/${type}/${id}.html`;
|
||||
const apiUrl = `https://api.dongqiudi.com/v3/archive/app/channel/feeds`;
|
||||
const { data: response } = await got(link);
|
||||
|
||||
let name;
|
||||
|
||||
const dom = new JSDOM(response.data, {
|
||||
const { window } = new JSDOM(response, {
|
||||
runScripts: 'dangerously',
|
||||
});
|
||||
|
||||
const data = dom.window.__NUXT__.data[0];
|
||||
const list = data.relatedNewsList;
|
||||
|
||||
const typeInfo = window.__NUXT__.data[0][`${type}Detail`].base_info;
|
||||
if (type === 'team') {
|
||||
name = data.teamDetail.base_info.team_name;
|
||||
name = typeInfo.team_name;
|
||||
} else if (type === 'player') {
|
||||
name = data.playerDetail.base_info.person_name;
|
||||
name = typeInfo.person_name;
|
||||
}
|
||||
const proList = [];
|
||||
|
||||
const { data } = await got(apiUrl, {
|
||||
searchParams: {
|
||||
id,
|
||||
type,
|
||||
size: 20,
|
||||
platform: 'web',
|
||||
version: '',
|
||||
},
|
||||
});
|
||||
|
||||
const list = data.data.articles.map((article) => ({
|
||||
title: article.title,
|
||||
link: `https://www.dongqiudi.com/articles/${article.id}.html`,
|
||||
category: [article.category, ...(article.secondary_category ? article.secondary_category : [])],
|
||||
pubDate: parseDate(article.show_time),
|
||||
}));
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map((item) => {
|
||||
const title = item.title;
|
||||
const link = `https://www.dongqiudi.com/news/${item.id}.html`;
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
|
||||
return ctx.cache.tryGet(link, () => {
|
||||
const single = {
|
||||
title,
|
||||
link,
|
||||
};
|
||||
ProcessFeedType2(item, response);
|
||||
|
||||
const es = got(link);
|
||||
proList.push(es);
|
||||
return single;
|
||||
});
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const responses = await got.all(proList);
|
||||
for (let i = 0; i < proList.length; i++) {
|
||||
ProcessFeedType2(out[i], responses[i].data);
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${name} - 相关新闻`,
|
||||
link,
|
||||
image: type === 'team' ? typeInfo.team_logo : typeInfo.person_logo,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
|
|
@ -134,7 +134,7 @@ const ProcessFeedType2 = (item, response) => {
|
|||
ProcessImg(body('img'));
|
||||
item.description = body.html();
|
||||
item.author = data.writer;
|
||||
item.pubDate = parseDate(data.show_time * 1000);
|
||||
item.pubDate = parseDate(data.show_time, 'X');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue