Skip to content

Commit

Permalink
feat(route): add 国家广播电视总局电视剧政务平台 (#12804)
Browse files Browse the repository at this point in the history
* feat(route): add 国家广播电视总局电视剧政务平台

* fix: set pool limit to 5
  • Loading branch information
nczitzk committed Jul 16, 2023
1 parent b9c8321 commit 79d848f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 3 deletions.
18 changes: 15 additions & 3 deletions docs/government.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,23 @@ pageClass: routes

### 分类

<Route author="yuxinliu-alex" example="/gov/nrta/news" path="/gov/nrta/news/:category?" :paramsDesc="['资讯类别, 可从地址中获取,默认为总局要闻']"/>
<Route author="yuxinliu-alex" example="/gov/nrta/news" path="/gov/nrta/news/:category?" :paramsDesc="['资讯类别,可从地址中获取,默认为总局要闻']"/>

| 总局要闻 | 公告公示 | 工作动态 | 其他 |
| :------: | :------: | :------: | :--: |
| 112 | 113 | 114 | |
| -------- | -------- | -------- | ---- |
| 112 | 113 | 114 | |

</Route>

### 电视剧政务平台

<Route author="nczitzk" example="/gov/nrta/dsj" path="/gov/nrta/dsj/:category?" :paramsDesc="['分类,见下表,默认为备案公示']">

| 备案公示 | 发行许可通告 | 重大题材立项 | 重大题材摄制 | 变更通报 |
| -------- | ------------ | ---------------- | --------------- | -------- |
| note | announce | importantLixiang | importantShezhi | changing |

</Route>

## 国家税务总局

Expand Down
1 change: 1 addition & 0 deletions lib/v2/gov/maintainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = {
'/nmpa/:path+': ['TonyRL'],
'/nopss/:path+': ['nczitzk'],
'/nrta/news/:category?': ['yuxinliu-alex'],
'/nrta/dsj/:category?': ['nczitzk'],
'/nsfc/news/:type?': ['Derekmini', 'nczitzk'],
'/pbc/goutongjiaoliu': ['nczitzk'],
'/pbc/gzlw': ['Fatpandac'],
Expand Down
59 changes: 59 additions & 0 deletions lib/v2/gov/nrta/dsj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const asyncPool = require('tiny-async-pool');

module.exports = async (ctx) => {
const { category = 'note' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 15;

const rootUrl = 'https://dsj.nrta.gov.cn';
const currentUrl = new URL(`tims/site/views/applications.shanty?appName=${category}`, rootUrl).href;

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

const $ = cheerio.load(response);

const items = $('img[src="/site/styles/default/images/icon_arrow_r.gif"]')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item).next();

const pubDateMatches = item.text().match(/(\d+年\d+月)/);

return {
title: item.text(),
link: new URL(item.prop('href'), rootUrl).href,
pubDate: pubDateMatches ? parseDate(pubDateMatches[1], ['YYYY年MM月', 'YYYY年M月']) : undefined,
};
});

const results = [];

for await (const item of asyncPool(5, items, (item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);

const content = cheerio.load(detailResponse);

content('table').last().remove();

item.description = content('td.newstext').html() || content('table').last().parent().parent().html();

return item;
})
)) {
results.push(item);
}

ctx.state.data = {
item: results,
title: `${$('title').text()}-${$('div.headbottom_menu_selected').text()}`,
link: currentUrl,
description: $('td').last().text(),
language: 'zh-cn',
image: $('img').first().prop('src'),
author: '国家广播电影电视总局电视剧管理司',
};
};
13 changes: 13 additions & 0 deletions lib/v2/gov/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,19 @@ module.exports = {
target: (params) => `/gov/nrta/news/${params.category.replace('col', '').replace('/index.html', '')}`,
},
],
dsj: [
{
title: '电视剧政务平台',
docs: 'https://docs.rsshub.app/government.html#guo-jia-guang-bo-dian-shi-zong-ju',
source: ['/tims/site/views/applications.shanty', '/'],
target: (params, url) => {
url = new URL(url);
const category = url.searchParams.get('appName');

return `/gov/nrta/dsj/${category}`;
},
},
],
},
'nsfc.gov.cn': {
_name: '国家自然科学基金委员会',
Expand Down
1 change: 1 addition & 0 deletions lib/v2/gov/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = function (router) {
router.get(/\/nmpa\/([\w][\w/]+)?/, require('./nmpa/generic'));
router.get(/nopss(\/[\w/-]+)?/, require('./nopss'));
router.get('/nrta/news/:category?', require('./nrta/news'));
router.get('/nrta/dsj/:category?', require('./nrta/dsj'));
router.get('/nsfc/news/:type?', require('./nsfc'));
router.get('/pbc/goutongjiaoliu', require('./pbc/goutongjiaoliu'));
router.get('/pbc/gzlw', require('./pbc/gzlw'));
Expand Down

0 comments on commit 79d848f

Please sign in to comment.