From b9efe9d588cf93c4d7043a92007d372f475b621e Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Fri, 30 Oct 2020 20:30:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20Deutsche=20Welle=20=E5=BE=B7?= =?UTF-8?q?=E5=9B=BD=E4=B9=8B=E5=A3=B0=20(#6047)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/new-media.md | 10 ++++++++ docs/new-media.md | 10 ++++++++ lib/router.js | 3 +++ lib/routes/dw/index.js | 52 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 lib/routes/dw/index.js diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 686a03cc35..b330d8a8a8 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -57,6 +57,16 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more +## Deutsche Welle + + + +| All | German Press | Culture | Economy | Science & Nature | +| ---- | -------- | -------- | -------- | -------- | +| all | press | cul | eco | sci | + + + ## Engadget ### Chinese diff --git a/docs/new-media.md b/docs/new-media.md index 2b9381f603..d8c7234158 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -118,6 +118,16 @@ pageClass: routes +## Deutsche Welle 德国之声 + + + +| 全部 | 德语媒体 | 文化经纬 | 经济纵横 | 科技环境 | +| ---- | -------- | -------- | -------- | -------- | +| all | press | cul | eco | sci | + + + ## DoNews ### 栏目 diff --git a/lib/router.js b/lib/router.js index 0775b23551..7c70942cff 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3404,6 +3404,9 @@ router.get('/dev.to/top/:period', require('./routes/dev.to/top')); router.get('/gameres/hot', require('./routes/gameres/hot')); router.get('/gameres/list/:id', require('./routes/gameres/list')); +// Deutsche Welle 德国之声 +router.get('/dw/:lang?/:caty?', require('./routes/dw/index')); + // Amazon router.get('/amazon/ku/:type?', require('./routes/amazon/ku')); diff --git a/lib/routes/dw/index.js b/lib/routes/dw/index.js new file mode 100644 index 0000000000..390204c04e --- /dev/null +++ b/lib/routes/dw/index.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const lang = ctx.params.lang || 'de'; + const caty = ctx.params.caty || 'all'; + + const currentUrl = `https://rss.dw.com/rdf/rss-${lang === 'zh' ? 'chi' : lang}-${caty}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + + const list = $('item') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.find('title').text(), + link: item.attr('rdf:about'), + pubDate: new Date(item.find('dc\\:date').text()).toUTCString(), + description: item.find('description').text(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + content('.col1').remove(); + item.description = content('.longText').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('channel title').text(), + link: response.data.match(/(.*)<\/link>/)[1], + item: items, + description: $('channel description').text(), + }; +};