feat: add Deutsche Welle 德国之声 (#6047)

This commit is contained in:
Ethan Shen
2020-10-30 12:30:52 +00:00
committed by GitHub
parent 10d0e0b2e9
commit b9efe9d588
4 changed files with 75 additions and 0 deletions
+10
View File
@@ -57,6 +57,16 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more
<RouteEn author="nczitzk" example="/cgtn/top" path="/cgtn/top"/>
## Deutsche Welle
<RouteEn author="nczitzk" example="/dw/en" path="/dw/:lang?/:caty?" :paramsDesc="['Language, can be found in the URL of the corresponding language version page, German by default', 'Category, all by default']">
| All | German Press | Culture | Economy | Science & Nature |
| ---- | -------- | -------- | -------- | -------- |
| all | press | cul | eco | sci |
</RouteEn>
## Engadget
### Chinese
+10
View File
@@ -118,6 +118,16 @@ pageClass: routes
<Route author="kt286" example="/cnbeta" path="/cnbeta"/>
## Deutsche Welle 德国之声
<Route author="nczitzk" example="/dw/zh" path="/dw/:lang?/:caty?" :paramsDesc="['语言,可在对应语言版本页的 URL 中找到,默认为德语', '分类,见下表,默认为全部']">
| 全部 | 德语媒体 | 文化经纬 | 经济纵横 | 科技环境 |
| ---- | -------- | -------- | -------- | -------- |
| all | press | cul | eco | sci |
</Route>
## DoNews
### 栏目
+3
View File
@@ -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'));
+52
View File
@@ -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>(.*)<\/link>/)[1],
item: items,
description: $('channel description').text(),
};
};