From 656c8bc08f132fd8d701dbb2d1745f92f0f6e376 Mon Sep 17 00:00:00 2001 From: Nishant Singh <57475999+Rjnishant530@users.noreply.github.com> Date: Tue, 8 Aug 2023 08:58:30 +0530 Subject: [PATCH] feat(route): add dnaindia (#12941) * feat(route): add dnaindia * Update docs/en/traditional-media.md Co-authored-by: Tony * Update docs/en/traditional-media.md Co-authored-by: Tony * Update docs/en/traditional-media.md Co-authored-by: Tony * Update docs/en/traditional-media.md Co-authored-by: Tony * Update docs/en/traditional-media.md Co-authored-by: Tony * Update lib/v2/dnaindia/radar.js Co-authored-by: Tony * Update lib/v2/dnaindia/radar.js Co-authored-by: Tony * Update lib/v2/dnaindia/radar.js Co-authored-by: Tony * Update: change logger and item.category * Update traditional-media.md * Update lib/v2/dnaindia/radar.js Co-authored-by: Tony * Update lib/v2/dnaindia/category.js --------- --- docs/en/traditional-media.md | 30 ++++++++++++++++ lib/v2/dnaindia/category.js | 66 +++++++++++++++++++++++++++++++++++ lib/v2/dnaindia/maintainer.js | 4 +++ lib/v2/dnaindia/radar.js | 19 ++++++++++ lib/v2/dnaindia/router.js | 4 +++ 5 files changed, 123 insertions(+) create mode 100644 lib/v2/dnaindia/category.js create mode 100644 lib/v2/dnaindia/maintainer.js create mode 100644 lib/v2/dnaindia/radar.js create mode 100644 lib/v2/dnaindia/router.js diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index 463e89696..d6cee7a29 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -242,6 +242,36 @@ Support all channels, refer to [CNBC RSS feeds](https://www.cnbc.com/rss-feeds/) +## DNA India + +### News + + + +Categories: + +| Headlines | Explainer | India | Entertainment | Sports | Viral | Lifestyle | Education | Business | World | +| --------- | --------- | ----- | ------------- | ------ | ----- | --------- | --------- | -------- | ----- | +| headlines | explainer | india | entertainment | sports | viral | lifestyle | education | business | world | + + + +### Topic + + + +Topics: + +|DNA verified| +|------------| +|dna-verified| + +::: tip Topic +See the URL for `https://www.dnaindia.com/topic/dna-verified` for the subdomain `topic` +::: + + + ## Financial Times ### myFT personal RSS diff --git a/lib/v2/dnaindia/category.js b/lib/v2/dnaindia/category.js new file mode 100644 index 000000000..c7c54264c --- /dev/null +++ b/lib/v2/dnaindia/category.js @@ -0,0 +1,66 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const logger = require('@/utils/logger'); + +module.exports = async (ctx) => { + const { category, topic } = ctx.params; + const baseUrl = 'https://www.dnaindia.com'; + let route; + if (category) { + route = `/${category}`; + } else if (topic) { + route = `/topic/${topic}`; + } else { + logger.error('Invalid URL'); + } + const { data: response } = await got(`${baseUrl}${route}`); + const $ = cheerio.load(response); + + const listItems = $('div.col-lg-6 div.list-news') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('div.explainer-subtext a'); + return { + title: a.text(), + link: `${baseUrl}${a.attr('href')}`, + }; + }); + + const items = await Promise.all( + listItems.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + item.itunes_item_image = $('div.article-img img').attr('src'); + item.category = $('div.tags ul li') + .toArray() + .map((item) => $(item).find('a').text()); + const time = $('p.dna-update').text().split('Updated:')[1]; + item.pubDate = timezone(parseDate(time, 'MMMDD,YYYY,hh:mmA'), +5.5); + item.author = 'DNA Web Team'; + item.description = $('div.article-description') + .clone() + .children('div') + .remove() + .end() + .toArray() + .map((element) => $(element).html()) + .join(''); + return item; + }) + ) + ); + + ctx.state.data = { + title: 'DNA India', + link: baseUrl, + item: items, + description: 'Latest News on dnaIndia.com', + logo: 'https://cdn.dnaindia.com/sites/all/themes/dnaindia/favicon-1016.ico', + icon: 'https://cdn.dnaindia.com/sites/all/themes/dnaindia/favicon-1016.ico', + language: 'en-us', + }; +}; diff --git a/lib/v2/dnaindia/maintainer.js b/lib/v2/dnaindia/maintainer.js new file mode 100644 index 000000000..047115429 --- /dev/null +++ b/lib/v2/dnaindia/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/:category': ['Rjnishant530'], + '/topic/:topic': ['Rjnishant530'], +}; diff --git a/lib/v2/dnaindia/radar.js b/lib/v2/dnaindia/radar.js new file mode 100644 index 000000000..a4edcd2c1 --- /dev/null +++ b/lib/v2/dnaindia/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'dnaindia.com': { + _name: 'DNA India', + '.': [ + { + title: 'News', + docs: 'https://docs.rsshub.app/en/traditional-media.html#dna-india', + source: ['/:category'], + target: '/dnaindia/:category', + }, + { + title: 'Topic', + docs: 'https://docs.rsshub.app/en/traditional-media.html#dna-india', + source: ['/topic/:topic'], + target: '/dnaindia/topic/:topic', + }, + ], + }, +}; diff --git a/lib/v2/dnaindia/router.js b/lib/v2/dnaindia/router.js new file mode 100644 index 000000000..b7dc590d7 --- /dev/null +++ b/lib/v2/dnaindia/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/:category', require('./category')); + router.get('/topic/:topic', require('./category')); +};