增加虎嗅网用户文章 (#1462)

以及时区 timezone util 类
This commit is contained in:
Henry Wang
2019-01-29 11:16:36 +00:00
committed by DIYgod
parent d2fafd71db
commit 21a7bf375c
4 changed files with 66 additions and 7 deletions

View File

@@ -2806,6 +2806,8 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
<route name="搜索" author="xyqfer" example="/huxiu/search/%E8%99%8E%E5%97%85%E6%97%A9%E6%8A%A5" path="/huxiu/search/:keyword" :paramsDesc="['关键字']" /> <route name="搜索" author="xyqfer" example="/huxiu/search/%E8%99%8E%E5%97%85%E6%97%A9%E6%8A%A5" path="/huxiu/search/:keyword" :paramsDesc="['关键字']" />
<route name="作者" author="HenryQW" example="/huxiu/author/29318" path="/huxiu/author/:id" :paramsDesc="['用户 id']" />
### 扇贝 ### 扇贝
<route name="打卡" author="DIYgod" example="/shanbay/checkin/ddwej" path="/shanbay/checkin/:id" :paramsDesc="['用户 id']" /> <route name="打卡" author="DIYgod" example="/shanbay/checkin/ddwej" path="/shanbay/checkin/:id" :paramsDesc="['用户 id']" />

View File

@@ -958,6 +958,7 @@ router.get('/zimuzu/resource/:id?', require('./routes/zimuzu/resource'));
// 虎嗅 // 虎嗅
router.get('/huxiu/tag/:id', require('./routes/huxiu/tag')); router.get('/huxiu/tag/:id', require('./routes/huxiu/tag'));
router.get('/huxiu/search/:keyword', require('./routes/huxiu/search')); router.get('/huxiu/search/:keyword', require('./routes/huxiu/search'));
router.get('/huxiu/author/:id', require('./routes/huxiu/author'));
// Steam // Steam
router.get('/steam/search/:params', require('./routes/steam/search')); router.get('/steam/search/:params', require('./routes/steam/search'));

View File

@@ -0,0 +1,61 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const date = require('../../utils/date');
module.exports = async (ctx) => {
const { id } = ctx.params;
const link = `https://www.huxiu.com/member/${id}.html`;
const host = 'https://www.huxiu.com';
const response = await axios({
method: 'get',
url: link,
headers: {
Referer: link,
},
});
const $ = cheerio.load(response.data);
const author = $('.user-name')
.text()
.trim();
const list = $('.message-box > .mod-art > a')
.slice(0, 10)
.get()
.map((e) => $(e).attr('href'));
const items = await Promise.all(
list.map(async (e) => {
const itemUrl = url.resolve(host, e);
const single = await ctx.cache.tryGet(
itemUrl,
async () => {
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
$('.neirong-shouquan, .neirong-shouquan-public').remove();
return {
title: $('.t-h1')
.text()
.trim(),
link: itemUrl,
description: $('.article-img-box').html() + $('.article-content-wrap').html(),
pubDate: date($('.article-time').text(), 8),
author,
};
},
2 * 24 * 60 * 60
);
return Promise.resolve(single);
})
);
const authorInfo = `虎嗅网 - ${author}`;
ctx.state.data = {
title: authorInfo,
link,
description: authorInfo,
item: items,
};
};

View File

@@ -1,6 +1,6 @@
const axios = require('../../../utils/axios'); const axios = require('../../../utils/axios');
const cheerio = require('cheerio'); const cheerio = require('cheerio');
// const timezone = require('../../utils/timezone'); const date = require('../../../utils/date');
module.exports = async (ctx) => { module.exports = async (ctx) => {
const { id } = ctx.params; const { id } = ctx.params;
@@ -24,7 +24,7 @@ module.exports = async (ctx) => {
link: `https://wemp.app${$(e) link: `https://wemp.app${$(e)
.find('.post-item__title') .find('.post-item__title')
.attr('href')}`, .attr('href')}`,
pubDate: timezone( pubDate: date(
`${year} ${$(e) `${year} ${$(e)
.find('.post-item__date') .find('.post-item__date')
.text() .text()
@@ -34,11 +34,6 @@ module.exports = async (ctx) => {
author, author,
})); }));
// to be replaced
function timezone(html, timezone) {
return new Date(new Date(html).getTime() - 60 * 60 * 1000 * (timezone + new Date().getTimezoneOffset() / 60)).toUTCString();
}
ctx.state.data = { ctx.state.data = {
title: `微信公众号 - ${author}`, title: `微信公众号 - ${author}`,
link: `https://wemp.app/accounts/${id}/`, link: `https://wemp.app/accounts/${id}/`,