Skip to content

Commit

Permalink
Merge pull request #743 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Jan 23, 2023
2 parents 0f18eda + 23e399e commit 2ba5ae2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,20 @@ category 对应的关键词有

<Route author="yuxinliu-alex" example="/chinanews" path="/chinanews" radar="1" rssbud="1" />

## 中国新闻周刊

### 栏目

提取文章全文。

<Route author="changren-wcr" example="/inewsweek/survey" path="/inewsweek/:channel" :paramsDesc="['栏目']">

| 封面 | 时政 | 社会 | 经济 | 国际 | 调查 | 人物 |
| ----- | -------- | ------- | ------- | ----- | ------ | ------ |
| cover | politics | society | finance | world | survey | people |

</Route>

## 中山网

### 中山网新闻
Expand Down
53 changes: 53 additions & 0 deletions lib/v2/inewsweek/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const iconv = require('iconv-lite');

const rootUrl = 'http://news.inewsweek.cn';

module.exports = async (ctx) => {
const channel = ctx.params.channel;
const url = `${rootUrl}/${channel}`;
const response = await got(url, {
responseType: 'buffer',
});
const $ = cheerio.load(iconv.decode(response.data, 'gbk'));
const items = await Promise.all(
$('div.grid-item')
.toArray()
.map((item) => {
item = $(item);
const href = item.find('a').attr('href');
const articleLink = `${rootUrl}${href}`;
return ctx.cache.tryGet(articleLink, async () => {
const response = await got(articleLink, {
responseType: 'buffer',
});

const $ = cheerio.load(iconv.decode(response.data, 'gbk'));
const fullText = $('div.contenttxt').html();
const time = timezone(
parseDate(
$('div.editor')
.html()
.split(/(\s\s+)/)[2]
),
+8
);
return {
title: item.find('p').text(),
description: fullText,
link: articleLink,
pubDate: time,
};
});
})
);

ctx.state.data = {
title: $('title').text(),
link: url,
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/inewsweek/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:channel': ['changren-wcr'],
};
13 changes: 13 additions & 0 deletions lib/v2/inewsweek/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'inewsweek.cn': {
_name: '中国新闻周刊',
'.': [
{
title: '栏目',
docs: 'https://docs.rsshub.app/traditional-media.html#zhong-guo-xin-wen-zhou-kan',
source: ['/:channel', '/'],
target: '/inewsweek/:channel',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/inewsweek/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:channel', require('./index'));
};

1 comment on commit 2ba5ae2

@vercel
Copy link

@vercel vercel bot commented on 2ba5ae2 Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.