-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(route): add 国务院政策文件库 * fix wrong author * typo * refactor: migrate to v2
- Loading branch information
Showing
12 changed files
with
209 additions
and
159 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 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 was deleted.
Oops, something went wrong.
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
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,55 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const timezone = require('@/utils/timezone'); | ||
|
||
module.exports = async (ctx) => { | ||
const { advance } = ctx.params; | ||
const link = `http://sousuo.gov.cn/list.htm`; | ||
const params = new URLSearchParams({ | ||
n: 20, | ||
t: 'govall', | ||
sort: 'pubtime', | ||
advance: 'true', | ||
}); | ||
const query = `${params.toString()}&${advance}`; | ||
const res = await got.get(link, { | ||
searchParams: query.replace(/([\u4e00-\u9fa5])/g, (str) => encodeURIComponent(str)), | ||
}); | ||
const $ = cheerio.load(res.data); | ||
|
||
const list = $('body > div.dataBox > table > tbody > tr') | ||
.slice(1) | ||
.toArray() | ||
.map((elem) => { | ||
elem = $(elem); | ||
return { | ||
title: elem.find('td:nth-child(2) > a').text(), | ||
link: elem.find('td:nth-child(2) > a').attr('href'), | ||
pubDate: timezone(parseDate(elem.find('td:nth-child(5)').text()), 8), | ||
}; | ||
}); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
let description = ''; | ||
try { | ||
const contentData = await got(item.link); | ||
const $ = cheerio.load(contentData.data); | ||
description = $('#UCAP-CONTENT').html(); | ||
} catch (error) { | ||
description = '文章已被删除'; | ||
} | ||
item.description = description; | ||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: '信息稿件 - 中国政府网', | ||
link: `${link}?${query}`, | ||
item: items, | ||
}; | ||
}; |
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,47 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const timezone = require('@/utils/timezone'); | ||
|
||
module.exports = async (ctx) => { | ||
const { pcodeJiguan } = ctx.params; | ||
const link = 'http://sousuo.gov.cn/list.htm'; | ||
const res = await got(link, { | ||
searchParams: { | ||
n: ctx.query.limit ? Number(ctx.query.limit) : 20, | ||
sort: 'pubtime', | ||
t: 'paper', | ||
pcodeJiguan: pcodeJiguan ? pcodeJiguan : '', | ||
}, | ||
}); | ||
const $ = cheerio.load(res.data); | ||
|
||
const list = $('body > div.dataBox > table > tbody > tr') | ||
.slice(1) | ||
.toArray() | ||
.map((elem) => { | ||
elem = $(elem); | ||
return { | ||
title: elem.find('td:nth-child(2) > a').text(), | ||
link: elem.find('td:nth-child(2) > a').attr('href'), | ||
pubDate: timezone(parseDate(elem.find('td:nth-child(5)').text()), 8), | ||
}; | ||
}); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const contentData = await got(item.link); | ||
const $ = cheerio.load(contentData.data); | ||
item.description = $('#UCAP-CONTENT').html(); | ||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: '最新文件 - 中国政府网', | ||
link: res.url, | ||
item: items, | ||
}; | ||
}; |
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,22 @@ | ||
const buildData = require('@/utils/common-config'); | ||
|
||
module.exports = async (ctx) => { | ||
const department = ctx.params.department; | ||
const link = `http://www.gov.cn/zhengce/zhengceku/${department}/`; | ||
|
||
ctx.state.data = await buildData({ | ||
link, | ||
url: link, | ||
title: `%title%`, | ||
description: '政府文件库, 当页的所有列表', | ||
params: { | ||
title: `$('.channel_tab > .noline > a').text().trim() + ' - 政府文件库'`, | ||
}, | ||
item: { | ||
item: '.news_box > .list > ul > li:not(.line)', | ||
title: `$('h4 > a').text()`, | ||
link: `$('h4 > a').attr('href')`, | ||
pubDate: `parseDate($('h4 > .date').text().trim())`, | ||
}, | ||
}); | ||
}; |
Oops, something went wrong.