forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(route): 中华人民共和国国家发展和改革委员会价格监测中心 (DIYgod#17201)
- Loading branch information
1 parent
29f4986
commit 5ea8917
Showing
1 changed file
with
95 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,125 @@ | ||
import { Route } from '@/types'; | ||
|
||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
import timezone from '@/utils/timezone'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
|
||
export const route: Route = { | ||
path: '/jgjcndrc/:id?', | ||
categories: ['government'], | ||
example: '/gov/jgjcndrc', | ||
parameters: { id: '栏目 id,见下表,默认为 692,即通知公告' }, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
name: '价格监测中心', | ||
maintainers: ['nczitzk'], | ||
handler, | ||
description: `| 通知公告 | 中心工作动态 | 地方工作动态 | 监测信息 | 分析预测 | 调查报告 | | ||
| -------- | ------------ | ------------ | -------- | -------- | -------- | | ||
| 692 | 693 | 694 | 695 | 696 | 697 | | ||
| 价格指数 | 地方价格监测 | 价格监测报告制度 | 监测法规 | 媒体聚焦 | | ||
| -------- | ------------ | ---------------- | -------- | -------- | | ||
| 698 | 699 | 700 | 701 | 753 | | ||
#### 监测信息 | ||
export const handler = async (ctx) => { | ||
const { columnId = '1832739866673426433', subColumnId } = ctx.req.param(); | ||
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 30; | ||
|
||
| 国内外市场价格监测情况周报 | 主要粮油副食品日报 | 生猪出厂价与玉米价格周报 | 国际市场石油价格每日 动态 | | ||
| -------------------------- | ------------------ | ------------------------ | ------------------------- | | ||
| 749 | 703 | 704 | 705 | | ||
const rootUrl = 'https://www.jgjcndrc.org.cn'; | ||
const currentUrl = new URL(`list?clmId=${columnId}${subColumnId ? `&sclmId=${subColumnId}` : ''}`, rootUrl).href; | ||
const apiColumnUrl = new URL(`prod-api/portal/artPageByColumn/${subColumnId ?? columnId}`, rootUrl).href; | ||
|
||
| 非学科类培训服务价格 | 监测周期价格动态 | 月度监测行情表 | 猪料、鸡料、蛋料比价 | | ||
| -------------------- | ---------------- | -------------- | -------------------- | | ||
| 821 | 706 | 707 | 708 |`, | ||
}; | ||
const { data: currentResponse } = await got(currentUrl); | ||
|
||
async function handler(ctx) { | ||
const { id = 'sytzgg' } = ctx.req.param(); | ||
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 30; | ||
const $ = load(currentResponse); | ||
|
||
const rootUrl = 'http://www.jgjcndrc.org.cn'; | ||
const currentUrl = new URL(`list.aspx?clmId=${id}`, rootUrl).href; | ||
const language = $('html').prop('lang'); | ||
|
||
const { data: response } = await got(currentUrl); | ||
const { data: response } = await got(apiColumnUrl, { | ||
searchParams: { | ||
pageNum: 1, | ||
pageSize: limit, | ||
}, | ||
}); | ||
|
||
const $ = load(response); | ||
let items = response.data.slice(0, limit).map((item) => { | ||
const guid = `jgjcndrc-${item.articleId}`; | ||
|
||
let items = $('ul.list_02 li.li a[title]') | ||
.slice(0, limit) | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
|
||
return { | ||
title: item.text(), | ||
link: new URL(item.prop('href'), rootUrl).href, | ||
pubDate: parseDate(item.prev().text()), | ||
}; | ||
}); | ||
return { | ||
title: item.articleTitle, | ||
pubDate: parseDate(item.pubDate), | ||
link: new URL(`prod-api/portal/article/${item.articleId}`, rootUrl).href, | ||
guid, | ||
id: guid, | ||
language, | ||
}; | ||
}); | ||
|
||
items = await Promise.all( | ||
items.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const { data: detailResponse } = await got(item.link); | ||
|
||
const content = load(detailResponse); | ||
|
||
item.title = content('div.txt_title1').text(); | ||
item.description = content('div#zoom').html(); | ||
item.pubDate = parseDate(content('div.txt_subtitle1').text().trim()); | ||
const data = detailResponse.data; | ||
|
||
const title = data.articleTitle; | ||
const description = data.articleContent; | ||
const guid = `jgjcndrc-${data.articleId}`; | ||
|
||
item.title = title; | ||
item.description = description; | ||
item.pubDate = timezone(parseDate(data.pubDate), +8); | ||
item.link = data.linkUrl || new URL(data.articleUrl, rootUrl).href; | ||
item.category = data.parentColumns.map((c) => c.columnName); | ||
item.guid = guid; | ||
item.id = guid; | ||
item.content = { | ||
html: description, | ||
text: description, | ||
}; | ||
item.language = language; | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
const author = $('title').text(); | ||
const subtitle = $('li.L').first().text(); | ||
const image = new URL($('img.logo2').prop('src'), rootUrl).href; | ||
const image = new URL($('header img').last().prop('src'), rootUrl).href; | ||
|
||
return { | ||
item: items, | ||
title: `${author} - ${subtitle}`, | ||
title: `${$('title').text()}${$('div.tit').text() ? ` - ${$('div.tit').text()}` : ''}`, | ||
description: $('meta[name="description"]').prop('content'), | ||
link: currentUrl, | ||
description: author, | ||
language: $('html').prop('lang'), | ||
item: items, | ||
allowEmpty: true, | ||
image, | ||
subtitle, | ||
author, | ||
author: $('header h1').text(), | ||
language, | ||
}; | ||
} | ||
}; | ||
|
||
export const route: Route = { | ||
path: '/jgjcndrc/:columnId?/:subColumnId?', | ||
name: '中华人民共和国国家发展和改革委员会价格监测中心', | ||
url: 'www.jgjcndrc.org.cn', | ||
maintainers: ['nczitzk'], | ||
handler, | ||
example: '/gov/jgjcndrc/1832739866673426433', | ||
parameters: { | ||
columnId: '栏目 id,默认为 `1832739866673426433`,即通知公告,可在对应栏目页 URL 中找到', | ||
subColumnId: '子栏目 id,默认为空,可在对应子栏目页 URL 中找到', | ||
}, | ||
description: `:::tip | ||
若订阅 [通知公告](https://www.jgjcndrc.org.cn/list?clmId=1832739866673426433),网址为 \`https://www.jgjcndrc.org.cn/list?clmId=1832739866673426433\`。截取 \`clmId\` 的参数部分 \`1832739866673426433\` 作为参数填入,此时路由为 [\`/gov/jgjcndrc/1832739866673426433\`](https://rsshub.app/gov/jgjcndrc/1832739866673426433)。 | ||
若订阅 [国内外市场价格监测情况周报](https://www.jgjcndrc.org.cn/list?clmId=1832298113994649601&sclmId=1832751799531220993),网址为 \`https://www.jgjcndrc.org.cn/list?clmId=1832298113994649601&sclmId=1832751799531220993\`。截取 \`clmId\` 和 \`sclmId\` 的参数部分 \`1832298113994649601\` 和 \`1832751799531220993\` 作为参数填入,此时路由为 [\`/gov/jgjcndrc/1832298113994649601/1832751799531220993\`](https://rsshub.app/gov/jgjcndrc/1832298113994649601/1832751799531220993)。 | ||
:::`, | ||
categories: ['government'], | ||
|
||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportRadar: true, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['www.jgjcndrc.org.cn/list'], | ||
target: (_, url) => { | ||
url = new URL(url); | ||
const columnId = url.searchParams.get('clmId'); | ||
const subColumnId = url.searchParams.get('sclmId'); | ||
|
||
return `/jgjcndrc${columnId ? `/${columnId}${subColumnId ? `/${subColumnId}` : ''}` : ''}`; | ||
}, | ||
}, | ||
], | ||
}; |