Skip to content

Commit

Permalink
Merge pull request #822 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 Feb 17, 2023
2 parents 26ec373 + 81a476e commit b2efd59
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 2 deletions.
12 changes: 12 additions & 0 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,18 @@ category 对应的关键词有

</Route>

### 侧边栏

<Route author="bigfei" example="/thepaper/sidebar/hotNews" path="/thepaper/sidebar/sec?" :paramsDesc="['边栏 id,如下, 默认hotNews']">

| 边栏 ID | 边栏名 |
| ------------------------ | ---- |
| hotNews | 澎湃热榜 |
| financialInformationNews | 澎湃财讯 |
| morningEveningNews | 早晚报 |

</Route>

### 明查

<Route author="nczitzk" example="/thepaper/factpaper" path="/thepaper/factpaper/:status?" :paramsDesc="['状态 id,可选 `1` 即 有定论 或 `0` 即 核查中,默认为 `1`']"/>
Expand Down
12 changes: 12 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,18 @@ category 列表:

<Route author="raptazure" example="/hitwh/today" path="/hitwh/today" radar="1" rssbud="1"/>

## 哈尔滨理工大学

### 教务处

<Route author="LenaNouzen" example="/hrbust/jwzx" path="/hrbust/jwzx/:type?/:page?" :paramsDesc="['分类名,默认为教务公告', '文章数,默认为12']" >

| 名师风采 | 热点新闻 | 教务公告 | 教学新闻 |
| ---- | ---- | ---- | ---- |
| 351 | 353 | 354 | 355 |

</Route>

## 海南大学

### 硕士研究生招生动态
Expand Down
36 changes: 36 additions & 0 deletions lib/v2/hrbust/jwzx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const got = require('@/utils/got');
const utils = require('./utils');

const typeMap = {
351: {
name: '名师风采',
},
353: {
name: '热点新闻',
},
354: {
name: '教务公告',
},
355: {
name: '教学新闻',
},
};

module.exports = async (ctx) => {
const page = ctx.params.page || '12';
const base = utils.columnIdBase(ctx.params.type) + '&pagingNumberPer=' + page;
const res = await got(base);
const info = utils.fetchAllArticle(res.data, utils.JWZXBASE);

const details = await Promise.all(info.map((e) => utils.detailPage(e, ctx.cache)));

// ctx.state.json = {
// info,
// };

ctx.state.data = {
title: '哈理工教务处' + typeMap[ctx.params.type || 354].name,
link: base,
item: details,
};
};
3 changes: 3 additions & 0 deletions lib/v2/hrbust/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/jwzx/:type?/:page?': ['LenaNouzen'],
};
13 changes: 13 additions & 0 deletions lib/v2/hrbust/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'hrbust.edu.cn': {
_name: '哈尔滨理工大学',
jwzx: [
{
title: '教务处',
docs: 'https://docs.rsshub.app/university.html#ha-er-bin-li-gong-da-xue',
source: '/homepage/*',
target: (params, url) => `/hrbust/jwzx/${url.match(/(?<=columnId=)\d+/)}`,
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/hrbust/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/jwzx/:type?/:page?', require('./jwzx'));
};
1 change: 1 addition & 0 deletions lib/v2/hrbust/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{@ desc }}
71 changes: 71 additions & 0 deletions lib/v2/hrbust/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

// const base = 'http://hrbust.edu.cn';
const jwzxBase = 'http://jwzx.hrbust.edu.cn/homepage/';

const columnIdBase = (id) => (id ? `${jwzxBase}infoArticleList.do?columnId=${id}` : `${jwzxBase}infoArticleList.do?columnId=354`);

const renderDesc = (desc) =>
art(path.join(__dirname, 'templates/description.art'), {
desc,
});

const detailPage = (e, cache) =>
cache.tryGet(e.detailPage, async () => {
const result = await got(e.detailPage);
const $ = cheerio.load(result.data);
const title = $('div#article h2').text().trim();
const desc =
$('div.body').html() &&
$('div.body')
.html()
.replace(/style="(.*?)"/g, '')
.trim();
const pubDate = timezone(
parseDate(
$('div#articleInfo ul li')
.first()
.text()
.replace(/发布日期:/g, '')
.trim()
),
+8
);
return {
title: e.title || title,
description: renderDesc(desc),
link: e.detailPage,
pubDate: e.pubDate || pubDate,
};
});

const fetchAllArticle = (data, base) => {
const $ = cheerio.load(data);
const article = $('.articleList li div');
const info = article
.map((i, e) => {
const c = cheerio.load(e);
const r = {
title: c('a').first().text().trim(),
detailPage: new URL(c('a').attr('href'), base).href,
pubDate: timezone(parseDate(c('span').first().text().trim()), +8),
};
return r;
})
.get();
return info;
};

module.exports = {
// BASE: base,
JWZXBASE: jwzxBase,
columnIdBase,
fetchAllArticle,
detailPage,
renderDesc,
};
3 changes: 2 additions & 1 deletion lib/v2/thepaper/maintainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
'/839studio': ['umm233'],
'/channel/:id': ['xyqfer', 'nczitzk', 'bigfei'],
'/featured': ['HenryQW', 'nczitzk', 'bigfei'],
'/factpaper/:status?': ['nczitzk'],
'/list/:id': ['nczitzk', 'bigfei'],
'/factpaper/:status?': ['nczitzk'],
'/sidebar/:sec?': ['bigfei'],
};
6 changes: 6 additions & 0 deletions lib/v2/thepaper/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ module.exports = {
source: ['/'],
target: '/thepaper/featured',
},
{
title: '侧边栏',
docs: 'https://docs.rsshub.app/traditional-media.html#peng-pai-xin-wen-ce-bian-lan',
source: ['/'],
target: '/thepaper/sidebar',
},
{
title: '频道',
docs: 'https://docs.rsshub.app/traditional-media.html#peng-pai-xin-wen-pin-dao',
Expand Down
3 changes: 2 additions & 1 deletion lib/v2/thepaper/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module.exports = function (router) {
router.get('/839studio', require('./839studio/studio'));
router.get('/839studio/:id', require('./839studio/category'));
router.get('/channel/:id', require('./channel'));
router.get('/list/:id', require('./list'));
router.get('/featured', require('./featured'));
router.get('/factpaper/:status?', require('./factpaper'));
router.get('/list/:id', require('./list'));
router.get('/sidebar/:sec?', require('./sidebar'));
};
24 changes: 24 additions & 0 deletions lib/v2/thepaper/sidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const utils = require('./utils');
const got = require('@/utils/got');

const sections = {
hotNews: '澎湃热榜',
financialInformationNews: '澎湃财讯',
morningEveningNews: '早晚报',
};

module.exports = async (ctx) => {
const { sec = 'hotNews' } = ctx.params;

const sidebar_url = `https://cache.thepaper.cn/contentapi/wwwIndex/rightSidebar`;
const sidebar_url_resp = await got(sidebar_url);
const sidebar_url_data = sidebar_url_resp.data;
const list = sidebar_url_data.data[sec];

const items = await Promise.all(list.filter((item) => item.contId).map((item) => utils.ProcessItem(item, ctx)));
ctx.state.data = {
title: `澎湃新闻 - ${sections[sec]}`,
item: items,
link: 'https://www.thepaper.cn',
};
};

1 comment on commit b2efd59

@vercel
Copy link

@vercel vercel bot commented on b2efd59 Feb 17, 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.