From 09f9cb941c6e220f6e9d0829be8a97b7501d39e8 Mon Sep 17 00:00:00 2001 From: jjlzg <63774757+jjlzg@users.noreply.github.com> Date: Mon, 24 Aug 2020 06:26:49 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E7=A6=8F=E5=BB=BA=E5=8F=8A?= =?UTF-8?q?=E7=A6=8F=E5=B7=9E=E6=96=B0=E9=97=BB=20(#5513)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: codefactor-io --- docs/traditional-media.md | 9 ++++++ lib/router.js | 10 +++++++ lib/routes/fjnews/fznews.js | 57 +++++++++++++++++++++++++++++++++++++ lib/routes/fjnews/jjnews.js | 44 ++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 lib/routes/fjnews/fznews.js create mode 100644 lib/routes/fjnews/jjnews.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 80cb416c2..210a92200 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -746,3 +746,12 @@ category 对应的关键词有 | article | blog | culture | reports | + +### 福建新闻 + + +### 福州新闻 + + +### 九江新闻 + diff --git a/lib/router.js b/lib/router.js index dfeae37e7..4a6eed93a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3101,4 +3101,14 @@ router.get('/justrun', require('./routes/justrun/index')); // 上海电力大学 router.get('/shiep/:type', require('./routes/universities/shiep/index')); +// 福建新闻 +router.get('/fjnews/fj/30', require('./routes/fjnews/fznews')); + +// 福州新闻 +router.get('/fjnews/fz/30', require('./routes/fjnews/fznews')); + +// 九江新闻jjnews +router.get('/fjnews/jjnews', require('./routes/fjnews/jjnews')); + + module.exports = router; diff --git a/lib/routes/fjnews/fznews.js b/lib/routes/fjnews/fznews.js new file mode 100644 index 000000000..5f41c9bcf --- /dev/null +++ b/lib/routes/fjnews/fznews.js @@ -0,0 +1,57 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); + +let host = 'http://news.fznews.com.cn/fzxw/'; +let citytitle = '福州新闻'; + +module.exports = async (ctx) => { + if (ctx.params.city === 'fj') { + host = 'http://news.fznews.com.cn/dsxw/'; + citytitle = '福建新闻'; + } else { + host = 'http://news.fznews.com.cn/fzxw/'; + citytitle = '福州新闻'; + } + + const response = await got.get(host); + const $ = cheerio.load(response.data); + const list = $('.li-h32f14 li:not(.clearfix)').slice(0, ctx.params.limit).get(); + const out = await Promise.all( + + list.map(async (item) => { + const $ = cheerio.load(item); + const title = $('a').text(); + const itemUrl = url.resolve(host, $('a').attr('href')); + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const res = await got.get(itemUrl); + const capture = cheerio.load(res.data); + const contents = capture('.zhengwen').html(); + const time = capture('div.laiyuan div.left').text().substring(0, 19); + const author = capture('.laiyuan').text().replace('分享到:', ''); + + const single = { + title, + link: itemUrl, + guid: itemUrl, + author: author, + description: contents, + pubDate: new Date(time).toUTCString(), + + }; + + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: citytitle, + link: host, + item: out, + }; +}; diff --git a/lib/routes/fjnews/jjnews.js b/lib/routes/fjnews/jjnews.js new file mode 100644 index 000000000..67e0f5a51 --- /dev/null +++ b/lib/routes/fjnews/jjnews.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); +const host = 'http://tt.m.jxnews.com.cn/jjtop/'; + +module.exports = async (ctx) => { + const response = await got.get(host); + const $ = cheerio.load(response.data); + const list = $('li.col-xs-12').get(); + const out = await Promise.all( + + list.map(async (item) => { + const $ = cheerio.load(item); + const title = $('.list-text-style').text(); + const itemUrl = url.resolve(host, $('a').attr('href')); + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const res = await got.get(itemUrl); + const capture = cheerio.load(res.data); + const contents = capture('content').html(); + const time = capture('div.col-xs-8').text().substring(0, 19); + + const single = { + title, + link: itemUrl, + guid: itemUrl, + description : contents, + pubDate : new Date(time).toUTCString(), + }; + + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title : '九江新闻', + link : host, + item : out, + }; +};