feat: add 福建及福州新闻 (#5513)

Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
jjlzg 2020-08-24 06:26:49 -05:00 committed by GitHub
parent 757708ca95
commit 09f9cb941c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 120 additions and 0 deletions

View File

@ -746,3 +746,12 @@ category 对应的关键词有
| article | blog | culture | reports |
</Route>
### 福建新闻
<Route author="jjlzg" example="/fjnews/fj/30" path="/fjnews/fznews"/>
### 福州新闻
<Route author="jjlzg" example="/fjnews/fz/30" path="/fjnews/fznews"/>
### 九江新闻
<Route author="jjlzg" example="/fjnews/jjnews" path="/fjnews/jjnews"/>

View File

@ -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;

View File

@ -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,
};
};

View File

@ -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,
};
};