From fe99193a9c9fb5f0aea3ce528fe5610bf62f1ce4 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Wed, 19 Oct 2022 07:55:45 -0500 Subject: [PATCH] feat(route): Add La Jornada news (#11091) * git commit -m "feat(route): Add La Jornada news" * fix(route): Lint for route * fix(route): get precise date * Update docs/en/traditional-media.md Co-authored-by: Tony * Update lib/v2/lajornada/router.js Co-authored-by: Tony * fix: radar * fix: maintainer --- docs/en/traditional-media.md | 24 +++++++++++++++ lib/v2/jornada/index.js | 59 ++++++++++++++++++++++++++++++++++++ lib/v2/jornada/maintainer.js | 3 ++ lib/v2/jornada/radar.js | 13 ++++++++ lib/v2/jornada/router.js | 3 ++ 5 files changed, 102 insertions(+) create mode 100644 lib/v2/jornada/index.js create mode 100644 lib/v2/jornada/maintainer.js create mode 100644 lib/v2/jornada/radar.js create mode 100644 lib/v2/jornada/router.js diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index ef793f5c7..f37283026 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -281,6 +281,30 @@ Support all channels, refer to [CNBC RSS feeds](https://www.cnbc.com/rss-feeds/) +## La Jornada + +### News + + + +Provides a way to get an specific rss feed by date and category over the official one. + +| Category | `:category`| +|------------------------|------------| +| Capital | capital | +| Cartones | cartones | +| Ciencia y Tecnología | ciencia | +| Cultura | cultura | +| Deportes | deportes | +| Economía | economia | +| Estados | estados | +| Mundo | mundo | +| Opinión | opinion | +| Política | politica | +| Sociedad | sociedad | + + + ## Ming Pao ### Ming Pao Daily diff --git a/lib/v2/jornada/index.js b/lib/v2/jornada/index.js new file mode 100644 index 000000000..a6fbb4224 --- /dev/null +++ b/lib/v2/jornada/index.js @@ -0,0 +1,59 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +const rootUrl = 'https://www.jornada.com.mx'; + +const categories = { + capital: 'Capital', + cartones: 'Cartones', + ciencia: 'Ciencia-Y-Tecnologia', + cultura: 'Cultura', + deportes: 'Deportes', + economia: 'Economia', + estados: 'Estados', + mundo: 'Mundo', + opinion: 'Opinion', + politica: 'Politica', + sociedad: 'Sociedad', +}; + +const getDateForToday = () => { + const date = new Date(Date.now()); + const today = date.getFullYear() + '-' + ('0' + (date.getMonth() + 1)).slice(-2) + '-' + ('0' + date.getDate()).slice(-2); + return today; +}; + +module.exports = async (ctx) => { + const date = ctx.params.date === 'today' || ctx.params.date === undefined ? getDateForToday() : ctx.params.date; + const category = ctx.params.category; + const url = `${rootUrl}/jsonstorage/articles_${date}_.json`; + + const response = await got(url); + const data = response.data; + + let items = {}; + + if (!category) { + items = data.map((item) => ({ + title: item.title, + description: item.content, + pubDate: parseDate(item.date), + link: `${rootUrl}/${item.url}`, + })); + } else { + const newsFilteredByCategory = data.filter((item) => item.category === categories[category]); + + items = newsFilteredByCategory.map((item) => ({ + title: item.title, + description: item.content, + pubDate: parseDate(item.date), + link: `${rootUrl}/${item.url}`, + })); + } + + ctx.state.data = { + title: 'La Jornada', + link: rootUrl, + item: items, + }; +}; diff --git a/lib/v2/jornada/maintainer.js b/lib/v2/jornada/maintainer.js new file mode 100644 index 000000000..538cf565b --- /dev/null +++ b/lib/v2/jornada/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:date?/:category?': ['Thealf154'], +}; diff --git a/lib/v2/jornada/radar.js b/lib/v2/jornada/radar.js new file mode 100644 index 000000000..cd878f6c4 --- /dev/null +++ b/lib/v2/jornada/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'jornada.com.mx': { + _name: 'La Jornada', + '.': [ + { + title: 'News', + docs: 'https://docs.rsshub.app/traditional-media.html#jornada', + source: ['/category/:category', '/'], + target: (params) => (params.category ? `/jornada/today/${params.category.replacce('.html', '')}` : `/jornada/today`), + }, + ], + }, +}; diff --git a/lib/v2/jornada/router.js b/lib/v2/jornada/router.js new file mode 100644 index 000000000..50bda59ba --- /dev/null +++ b/lib/v2/jornada/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:date?/:category?', require('./index')); +};