Skip to content

Commit

Permalink
feat(route): use API for stheadline.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzx-dzx committed Sep 3, 2023
1 parent 37404f2 commit d6c73e5
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions lib/v2/stheadline/std/realtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,52 @@ module.exports = async (ctx) => {
const { data: response } = await got(url);
const $ = cheerio.load(response);

const items = $(`${category === '即時' ? '.moreNews > .col-md-4' : ''} .media-body > .my-2 > a`)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.attr('title'),
link: item.attr('href'),
guid: item.attr('href').substring(0, item.attr('href').lastIndexOf('/')),
const items = (
await (async () => {
const headers = {
'Accept-Language': 'en-US,en;q=0.5',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
};
});
if (category === '即時') {
const res = await got
.post('https://std.stheadline.com/realtime/get_more_instant_news', {
headers,
form: {
page: 1,
},
})
.json();
return res;
} else {
const res = await got
.post('https://std.stheadline.com/realtime/get_more_news', {
headers,
form: {
page: 1,
cat: category,
},
})
.json();
return res;
}
})()
).data.map((e) => ({
title: e.title,
link: e.articleLink,
guid: e.articleLink.substring(0, e.articleLink.lastIndexOf('/')),
pubDate: timezone(parseDate(e.publish_datetime), +8),
}));

// const items = $(`${category === '即時' ? '.moreNews > .col-md-4' : ''} .media-body > .my-2 > a`)
// .toArray()
// .map((item) => {
// item = $(item);
// return {
// title: item.attr('title'),
// link: item.attr('href'),
// guid: item.attr('href').substring(0, item.attr('href').lastIndexOf('/')),
// };
// });

await Promise.all(
items.map((item) =>
Expand All @@ -29,7 +65,6 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response);

item.description = $('.paragraphs').html();
item.pubDate = timezone(parseDate($('.content .date').text()), +8);

return item;
})
Expand Down

0 comments on commit d6c73e5

Please sign in to comment.