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.
Merge pull request #2242 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
20 changed files
with
543 additions
and
205 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
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const { category } = ctx.params; | ||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 5; | ||
|
||
const domain = 'moa.gov.cn'; | ||
const rootFrameUrl = `http://www.${domain}`; | ||
const rootUrl = `http://zdscxx.${domain}:8080`; | ||
const apiUrl = new URL('nyb/getMessages', rootUrl).href; | ||
const apiDetailUrl = new URL('nyb/getMessagesById', rootUrl).href; | ||
const currentUrl = new URL('nyb/pc/messageList.jsp', rootUrl).href; | ||
const frameUrl = new URL('iframe/top_sj/', rootFrameUrl).href; | ||
|
||
let filterForm = {}; | ||
|
||
if (category) { | ||
const apiFilterUrl = new URL('nyb/getMessageFilters', rootUrl).href; | ||
|
||
const { data: filterResponse } = await got.post(apiFilterUrl, { | ||
form: { | ||
type: '', | ||
isLatestMessage: false, | ||
}, | ||
}); | ||
|
||
const filters = filterResponse.result.reduce((filters, f) => { | ||
filters[f.name] = f.data.map((d) => d.name); | ||
return filters; | ||
}, {}); | ||
|
||
filterForm = category.split(/\//).reduce((form, c) => { | ||
Object.keys(filters) | ||
.filter((key) => filters[key].includes(c)) | ||
.forEach((key) => { | ||
form[key] = c; | ||
}); | ||
return form; | ||
}, {}); | ||
} | ||
|
||
const { data: response } = await got.post(apiUrl, { | ||
form: { | ||
page: 1, | ||
rows: limit, | ||
type: '', | ||
isLatestMessage: false, | ||
...filterForm, | ||
}, | ||
}); | ||
|
||
let items = response.result.table.slice(0, limit).map((item) => ({ | ||
title: item.title, | ||
link: item.id, | ||
guid: `moa-zdscxx-${item.id}`, | ||
pubDate: parseDate(item.date), | ||
})); | ||
|
||
items = await Promise.all( | ||
items.map((item) => | ||
ctx.cache.tryGet(item.guid, async () => { | ||
const { data: detailResponse } = await got.post(apiDetailUrl, { | ||
form: { | ||
id: item.link, | ||
}, | ||
}); | ||
|
||
const data = detailResponse.result; | ||
|
||
item.title = data.title; | ||
item.link = new URL(`nyb/pc/messageView.jsp?id=${item.link}`, rootUrl).href; | ||
item.description = data.content; | ||
item.author = data.source; | ||
item.pubDate = parseDate(data.date); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
const { data: frameResponse } = await got(frameUrl); | ||
|
||
const $ = cheerio.load(frameResponse); | ||
|
||
const title = $('title').text(); | ||
const description = '数据'; | ||
const icon = new URL('favicon.ico', rootUrl).href; | ||
|
||
ctx.state.data = { | ||
item: items, | ||
title: `${title} - ${description} - ${category}`, | ||
link: currentUrl, | ||
description, | ||
language: 'zh', | ||
image: $('h1.logo a img').prop('src'), | ||
icon, | ||
logo: icon, | ||
subtitle: category, | ||
author: title, | ||
allowEmpty: true, | ||
}; | ||
}; |
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
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
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const timezone = require('@/utils/timezone'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const { category = 'zuixin' } = ctx.params; | ||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20; | ||
|
||
const rootUrl = 'https://www.gov.cn'; | ||
const currentUrl = new URL(`zhengce/${category.replace(/\/$/, '')}/`, rootUrl).href; | ||
|
||
const { data: response } = await got(currentUrl); | ||
|
||
const $ = cheerio.load(response); | ||
|
||
let items = $('h4 a, div.subtitle a[title]') | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
|
||
const link = item.prop('href'); | ||
|
||
return { | ||
title: item.text(), | ||
link: link.startsWith('http') ? link : new URL(link, currentUrl).href, | ||
}; | ||
}); | ||
|
||
items = await Promise.all( | ||
items | ||
.filter((item) => /https?:\/\/www\.gov\.cn\/zhengce.*content_\d+\.htm/.test(item.link)) | ||
.slice(0, limit) | ||
.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const { data: detailResponse } = await got(item.link); | ||
|
||
const content = cheerio.load(detailResponse); | ||
|
||
const processElementText = (el) => content(el).text().split(/:/).pop().trim() || content(el).next().text().trim(); | ||
|
||
const author = content('meta[name="author"]').prop('content'); | ||
|
||
const agencyEl = content('table.bd1') | ||
.find('td') | ||
.toArray() | ||
.filter((a) => content(a).text().startsWith('发文机关')) | ||
.pop(); | ||
|
||
const sourceEl = content('span.font-zyygwj') | ||
.toArray() | ||
.filter((a) => content(a).text().startsWith('来源')) | ||
.pop(); | ||
|
||
const subjectEl = content('table.bd1') | ||
.find('td') | ||
.toArray() | ||
.filter((a) => content(a).text().startsWith('主题分类')) | ||
.pop(); | ||
|
||
const agency = agencyEl ? processElementText(agencyEl) : undefined; | ||
const source = sourceEl ? processElementText(sourceEl) : undefined; | ||
const subject = subjectEl ? processElementText(subjectEl) : content('td.zcwj_ztfl').text(); | ||
|
||
const column = content('meta[name="lanmu"]').prop('content'); | ||
const keywords = content('meta[name="keywords"]').prop('content')?.split(/;|,/) ?? []; | ||
const manuscriptId = content('meta[name="manuscriptId"]').prop('content'); | ||
|
||
item.title = content('div.share-title').text() || item.title; | ||
item.description = content('div.TRS_UEDITOR').first().html() || content('div#UCAP-CONTENT, td#UCAP-CONTENT').first().html(); | ||
item.author = [agency, source, author].filter((a) => a).join('/'); | ||
item.category = [...new Set([subject, column, ...keywords].filter((c) => c))]; | ||
item.guid = `gov-zhengce-${manuscriptId}`; | ||
item.pubDate = timezone(parseDate(content('meta[name="firstpublishedtime"]').prop('content'), 'YYYY-MM-DD-HH:mm:ss'), +8); | ||
item.updated = timezone(parseDate(content('meta[name="lastmodifiedtime"]').prop('content'), 'YYYY-MM-DD-HH:mm:ss'), +8); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
const image = new URL($('img.wordlogo').prop('src'), rootUrl).href; | ||
const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; | ||
const subtitle = $('meta[name="lanmu"]').prop('content'); | ||
const author = $('div.header_logo a[aria-label]').prop('aria-label'); | ||
|
||
ctx.state.data = { | ||
item: items, | ||
title: author && subtitle ? `${author} - ${subtitle}` : $('title').text(), | ||
link: currentUrl, | ||
description: $('meta[name="description"]').prop('content'), | ||
language: 'zh-CN', | ||
image, | ||
icon, | ||
logo: icon, | ||
subtitle, | ||
author, | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.