Skip to content

Commit

Permalink
feat(route): add NDDaily 南方都市报 (#12370)
Browse files Browse the repository at this point in the history
* feat(route): add NDDaily 南方都市报

* fix(route): fix empty pubDate of NDDaily

* fix(route): fix pubDate of NDDaily

* fix(route): rename nddaily to oeeee

* fix(route): rename nddaily to oeeee
  • Loading branch information
TimWu007 authored Apr 27, 2023
1 parent 1e8d030 commit 5b90d88
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,33 @@ category 对应的关键词有

</Route>

## 南方都市报

### 奥一网

<Route author="TimWu007" example="/oeeee/web/170" path="/oeeee/web/:channel" :paramsDesc="['频道 ID']">

- 若在桌面端打开奥一网栏目页(如 <https://www.oeeee.com/api/channel.php?s=/index/index/channel/gz),可查看该页源代码,搜索> `OECID`
- 若在移动端打开奥一网栏目页(格式例:<https://m.oeeee.com/m.php?s=/m2/channel&channel_id=169),即可从> url 中获取。需注意的是,如果该栏目页的 url 格式为 <https://m.oeeee.com/detailChannel_indexData.html?channel_id=266> ,则 `266` 并非为本路由可用的频道 ID,建议从桌面端获取。

</Route>

### 南都客户端(按南都号 ID)

<Route author="TimWu007" example="/oeeee/app/channel/50" path="/oeeee/app/channel/:id?" :paramsDesc="['南都号 ID']">

南都号的 UID 可通过 `m.mp.oeeee.com` 下的文章页面获取。点击文章上方的南都号头像,进入该南都号的个人主页,即可从 url 中获取。

</Route>

### 南都客户端(按记者)

<Route author="TimWu007" example="/oeeee/app/reporter/249" path="/oeeee/app/reporter/:id" :paramsDesc="['记者 UID']">

记者的 UID 可通过 `m.mp.oeeee.com` 下的文章页面获取。点击文章下方的作者头像,进入该作者的个人主页,即可从 url 中获取。

</Route>

## 南方网

### 南方 +(按栏目 ID)
Expand Down
36 changes: 36 additions & 0 deletions lib/v2/oeeee/app/channel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { parseArticle } = require('../utils');
const { art } = require('@/utils/render');
const path = require('path');

module.exports = async (ctx) => {
const id = ctx.params.id ?? 50;
const currentUrl = `https://api-ndapp.oeeee.com/friends.php?m=Zone&a=SpaceDoclist&uid=${id}&type=doc`;

const { data: response } = await got(currentUrl);

const list = response.data
.filter((i) => i.url) // Remove banner and sticky articles.
.map((item) => ({
title: item.title,
description: art(path.join(__dirname, '../templates/description.art'), {
thumb: item.titleimg.replace(/\?x-oss-process=.*/g, ''),
description: item.summary,
}),
pubDate: timezone(parseDate(item.ptime * 1000), +8),
link: item.url,
channel: item.author,
}));

const channel = list[1] ? list[1].channel : '';

const items = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet)));

ctx.state.data = {
title: `南方都市报客户端 - ${channel}`,
link: `https://m.mp.oeeee.com/u/${id}.html`,
item: items,
};
};
30 changes: 30 additions & 0 deletions lib/v2/oeeee/app/reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const got = require('@/utils/got');
const { parseArticle } = require('../utils');
const { art } = require('@/utils/render');
const path = require('path');

module.exports = async (ctx) => {
const id = ctx.params.id ?? 0;
const currentUrl = `https://m.mp.oeeee.com/show.php?m=Doc&a=getAuthorInfo&id=${id}`;

const { data: response } = await got(currentUrl);

const list = response.data.list.map((item) => ({
title: '【' + item.media_nickname + '】' + item.title,
description: art(path.join(__dirname, '../templates/description.art'), {
thumb: item.titleimg,
description: item.summary,
}),
link: item.url,
}));

const author = response.data.info ? response.data.info.name : '';

const items = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet)));

ctx.state.data = {
title: `南方都市报奥一网 - ${author}`,
link: `https://m.mp.oeeee.com/w/${id}.html`,
item: items,
};
};
5 changes: 5 additions & 0 deletions lib/v2/oeeee/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
'/web/:channel': ['TimWu007'],
'/app/channel/:id': ['TimWu007'],
'/app/reporter/:id': ['TimWu007'],
};
12 changes: 12 additions & 0 deletions lib/v2/oeeee/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
'oeeee.com': {
_name: '奥一网',
'.': [
{
title: '新闻',
docs: 'https://docs.rsshub.app/traditional-media.html#nan-fang-du-shi-bao',
source: ['/'],
},
],
},
};
5 changes: 5 additions & 0 deletions lib/v2/oeeee/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = (router) => {
router.get('/web/:channel', require('./web'));
router.get('/app/channel/:id', require('./app/channel'));
router.get('/app/reporter/:id', require('./app/reporter'));
};
7 changes: 7 additions & 0 deletions lib/v2/oeeee/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ if thumb }}
<img src="{{ thumb }}"><br>
{{ /if }}
{{ if description }}
<blockquote><p>{{ description }}</p></blockquote>
<br>
{{ /if }}
41 changes: 41 additions & 0 deletions lib/v2/oeeee/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

const parseArticle = (item, tryGet) =>
tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});

const content = cheerio.load(detailResponse.data);

// nfapp page:
if (content('.post-cont') && content('.post-cont').html()) {
content('img').removeAttr('data-width').removeAttr('data-height').removeAttr('class').removeAttr('title').removeAttr('referrerpolicy');
content('.taglist, .J_ndlogo, .zan-shang, .sourcelist-box, #shareContain, .buyCopyright, .article-info, .icon, .special').remove();
item.description +=
content('.post-cont')
.html()
.replace(/data:image\S*=="\s*\n*\s*original="/g, '') ?? '';
if (!item.pubDate) {
item.pubDate = timezone(parseDate(content('.introduce').text().split()), +8);
}
}
// oeeee news page:
else if (content('.content') && content('.content').html()) {
item.description += content('.content').html() ?? '';
}
// oeeee news page #2:
else if (content('.article-conten') && content('.article-conten').html()) {
item.description += content('.article-conten').html() ?? '';
}

return item;
});

module.exports = {
parseArticle,
};
36 changes: 36 additions & 0 deletions lib/v2/oeeee/web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { parseArticle } = require('./utils');
const { art } = require('@/utils/render');
const path = require('path');

module.exports = async (ctx) => {
const channel = ctx.params.channel ?? 0;
const currentUrl = `https://www.oeeee.com/api/channel.php?m=Js4channelNews&a=newLatest&cid=${channel}`;

const { data: response } = await got(currentUrl);

const list = response.data.map((item) => ({
title: '【' + item.channel_name + '】' + item.title,
description: art(path.join(__dirname, 'templates/description.art'), {
thumb: item.img,
description: item.summary,
}),
pubDate: timezone(parseDate(item.datetime), +8),
link: item.linkurl,
author: item.author,
// channelName: item.channel_name,
channelEname: item.channel_ename,
}));

const channelEname = list[1] ? list[1].channelEname : '';

const items = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet)));

ctx.state.data = {
title: `南方都市报奥一网`,
link: `https://www.oeeee.com/api/channel.php?s=/index/index/channel/${channelEname}`,
item: items,
};
};

0 comments on commit 5b90d88

Please sign in to comment.