Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add Kantar Worldpanel News Centre #13199

Merged
merged 7 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions lib/v2/kantarworldpanel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');

module.exports = async (ctx) => {
const { region = 'cn-en', category = 'news' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;

const rootUrl = 'https://www.kantarworldpanel.com/';
const currentUrl = new URL(`${region}/${category}`, rootUrl).href;

const { data: response } = await got(currentUrl);

const $ = cheerio.load(response);

let items = $('ul.slide, #newssource')
.find('li')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);

const a = item.find('a');
const image = item.find('img');

const title = item.find('h3.mediumFont').text().trim();

let link = a.prop('href');
link = link === '#' ? currentUrl : link;

return {
title,
link,
description: art(path.join(__dirname, 'templates/description.art'), {
description: item.find('p.gowhite').text(),
image: image.prop('src')
? {
src: image.prop('src'),
alt: image.prop('alt'),
}
: undefined,
}),
guid: link.startsWith(rootUrl) ? `${link}#${title}` : link,
pubDate: parseDate(item.find('p.medGrey').text(), 'DD/MM/YYYY'),
};
});

items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
// The URL similar to the example below is the file download URL.
// eg. https://www.kantarworldpanel.com/dwl.php?sn=publications&id=1632.
if (item.link === currentUrl || !item.link.startsWith(rootUrl)) {
return item;
} else if (/dwl\.php/.test(item.link)) {
item.enclosure_url = item.link;
item.enclosure_type = 'application/pdf';

return item;
}

const detailResponse = await got(item.link);

if (!detailResponse.url.startsWith(rootUrl)) {
return item;
}

const content = cheerio.load(detailResponse.data);

item.title = content('h1.newshead').text();
item.description = content('div.center-content div.left-layout-col').html();
item.category = content('meta[name="keywords"]').prop('content')?.split(/,\s?/) ?? [];
item.pubDate = parseDate(content('p.newsdateshare').text(), 'DD/MM/YYYY');

return item;
})
)
);

const icon = new URL('favicon.ico', rootUrl).href;

ctx.state.data = {
item: items,
title: $('title').text(),
link: currentUrl,
description: $('meta[name="description"]').prop('content'),
language: $('html').prop('lang'),
image: $('#logoprint img').prop('src'),
icon,
logo: icon,
subtitle: $('meta[name="keywords"]').prop('content'),
allowEmpty: true,
};
};
3 changes: 3 additions & 0 deletions lib/v2/kantarworldpanel/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:region/:category?': ['nczitzk'],
};
199 changes: 199 additions & 0 deletions lib/v2/kantarworldpanel/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
module.exports = {
'kantarworldpanel.com': {
_name: 'Kantar Worldpanel',
'.': [
{
title: 'News Centre China Eng - News',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/cn-en/news'],
target: '/kantarworldpanel/cn-en/news',
},
{
title: 'News Centre China Eng - Retail Snapshot',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/cn-en/publications'],
target: '/kantarworldpanel/cn-en/publications',
},
{
title: 'News Centre China Eng - Publications',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/cn-en/publications/Reports'],
target: '/kantarworldpanel/cn-en/publications/Reports',
},
{
title: 'News Centre China Eng - In the media',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/cn-en/In-the-media'],
target: '/kantarworldpanel/cn-en/In-the-media',
},
{
title: 'News Centre China 中文 - 新闻发布',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/cn/news'],
target: '/kantarworldpanel/cn/news',
},
{
title: 'News Centre China 中文 - 零售市场快报',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/cn/publications'],
target: '/kantarworldpanel/cn/publications',
},
{
title: 'News Centre China 中文 - 市场报告',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/cn/publications/China-Insights'],
target: '/kantarworldpanel/cn/publications/China-Insights',
},
{
title: 'News Centre China 中文 - 媒体报道',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/cn/press-releases'],
target: '/kantarworldpanel/cn/press-releases',
},
{
title: 'News Centre Indonesia - News',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/id/News'],
target: '/kantarworldpanel/id/News',
},
{
title: 'News Centre Indonesia - Kantar Scoop',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/id/News/Kantar-Worldpanel-Series'],
target: '/kantarworldpanel/id/News/Kantar-Worldpanel-Series',
},
{
title: 'News Centre Indonesia - Video Series',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/id/News/video-series'],
target: '/kantarworldpanel/id/News/video-series',
},
{
title: 'News Centre Indonesia - Podcast',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/id/News/podcast'],
target: '/kantarworldpanel/id/News/podcast',
},
{
title: 'News Centre Indonesia - Ready, Steady, Shop!',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/id/News/asia-shopper-series'],
target: '/kantarworldpanel/id/News/asia-shopper-series',
},
{
title: 'News Centre Indonesia - Asia Pulse',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/id/News/Asia-Pulse'],
target: '/kantarworldpanel/id/News/Asia-Pulse',
},
{
title: 'News Centre Korea - News',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/kr/news'],
target: '/kantarworldpanel/kr/news',
},
{
title: 'News Centre Korea - Insight Reports',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/kr/publications'],
target: '/kantarworldpanel/kr/publications',
},
{
title: 'News Centre Korea - In the Media',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/kr/press-releases'],
target: '/kantarworldpanel/kr/press-releases',
},
{
title: 'News Centre Malaysia - News',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/my/news'],
target: '/kantarworldpanel/my/news',
},
{
title: 'News Centre Philippines - Latest Insights',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/ph/Latest-Insights'],
target: '/kantarworldpanel/ph/Latest-Insights',
},
{
title: 'News Centre Philippines - In the Media',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/ph/In-the-Media'],
target: '/kantarworldpanel/ph/In-the-Media',
},
{
title: 'News Centre Philippines - Events',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/ph/events'],
target: '/kantarworldpanel/ph/events',
},
{
title: 'News Centre Taiwan - 聚焦台灣',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/ph/news/spotlight-on-taiwan'],
target: '/kantarworldpanel/tw/news/spotlight-on-taiwan',
},
{
title: 'News Centre Taiwan - WOW SPOT',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/tw/news/wowspot'],
target: '/kantarworldpanel/tw/news/wowspot',
},
{
title: 'News Centre Taiwan - 市場報告',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/tw/publications'],
target: '/kantarworldpanel/tw/publications',
},
{
title: 'News Centre Taiwan - 媒體報導',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/tw/press-releases'],
target: '/kantarworldpanel/tw/press-releases',
},
{
title: 'News Centre Taiwan - 活動',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/tw/events'],
target: '/kantarworldpanel/tw/events',
},
{
title: 'News Centre Thailand - News',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/th/news'],
target: '/kantarworldpanel/th/news',
},
{
title: 'News Centre Vietnam - Insights',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/vn/news'],
target: '/kantarworldpanel/vn/news',
},
{
title: 'News Centre Vietnam - FMCG Monitor',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/vn/news/FMCG-Monitor'],
target: '/kantarworldpanel/vn/news/FMCG-Monitor',
},
{
title: 'News Centre Vietnam - Ready, Steady, Shop!',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/vn/news/ready-steady-shop'],
target: '/kantarworldpanel/vn/news/ready-steady-shop',
},
{
title: 'News Centre Vietnam - Asia Pulse',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/vn/news/asia-pulse'],
target: '/kantarworldpanel/vn/news/asia-pulse',
},
{
title: 'News Centre Vietnam - IN THE MEDIA',
docs: 'https://docs.rsshub.app/routes/new-media#kanta-worldpanel-news-centre',
source: ['/vn/In-the-media'],
target: '/kantarworldpanel/vn/In-the-media',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/kantarworldpanel/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:region?/:category*', require('./'));
};
9 changes: 9 additions & 0 deletions lib/v2/kantarworldpanel/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ if description }}
{{@ description }}
{{ /if }}

{{ if image }}
<figure>
<img src="{{ image }}">
</figure>
{{ /if }}
Loading