为中国地震局信息和Bangumi.tv的信息添加pubDate (#509)

为中国地震局信息和Bangumi.tv的信息添加pubDate;
修正地震信息内容显式的BUG
This commit is contained in:
叡山电车 2018-08-22 14:40:04 +08:00 committed by DIYgod
parent cd6c3a1e19
commit 0e847d2233
6 changed files with 65 additions and 6 deletions

View File

@ -249,6 +249,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- 游记
- 江南大学
- 教务处通知
- 中国地震局
- 震情速报
</details>

View File

@ -55,6 +55,7 @@
"koa-favicon": "2.0.1",
"koa-router": "7.4.0",
"lru-cache": "4.1.3",
"luxon": "^1.3.3",
"markdown-it": "^8.4.2",
"path-to-regexp": "2.2.1",
"raven": "^2.6.3",

View File

@ -1,5 +1,6 @@
const axios = require('../../../utils/axios');
const cheerio = require('cheerio');
const DateTime = require('luxon').DateTime;
module.exports = async (ctx) => {
// bangumi.tv未提供获取小组话题的API因此仍需要通过抓取网页来获取
@ -16,6 +17,13 @@ module.exports = async (ctx) => {
id: $el.attr('id'),
author: $el.find('.userInfo .l').text(),
content: $el.find('.reply_content .message').html(),
date: $el
.children()
.first()
.find('small')
.children()
.remove()
.end().text().slice(3),
};
})
.get()
@ -28,6 +36,7 @@ module.exports = async (ctx) => {
title: `${c.author}回复了小组话题《${title}`,
description: c.content,
guid: c.id,
pubDate: DateTime.fromFormat(c.date, 'yyyy-L-dd HH:mm'),
link,
})),
};

View File

@ -1,5 +1,6 @@
const axios = require('../../../utils/axios');
const cheerio = require('cheerio');
const DateTime = require('luxon').DateTime;
module.exports = async (subjectID, minLength) => {
// bangumi.tv未提供获取“吐槽comments”的API因此仍需要通过抓取网页来获取
@ -17,10 +18,31 @@ module.exports = async (subjectID, minLength) => {
if ($rateEl.length > 0) {
rate = $rateEl.attr('class').match(/sstars(\d)/)[1];
}
let dateString = $el.find('small.grey').text().slice(2);
let date;
if(dateString.includes('ago')) {
// 处理表示相对日期的字符串
const list = dateString
.match(/(\dd )?(\d{1,2}h )?(\d{1,2}m )?ago/)
.slice(1)
.map(s => s ? Number(s.slice(0, -2)) : 0);
date = DateTime.local().minus({
days: list[0],
hours: list[1],
minutes: list[2],
});
} else {
// 表示绝对日期的字符串
date = DateTime.fromFormat(dateString, 'yyyy-L-dd HH:mm');
}
return {
user: $el.find('.l').text(),
rate: rate ? rate / 2 : '无',
rate: rate || '无',
content: $el.find('p').text(),
date: date.toRFC2822(),
};
})
.get()
@ -32,6 +54,7 @@ module.exports = async (subjectID, minLength) => {
title: `${c.user}的吐槽`,
description: `【评分:${c.rate}${c.content}`,
guid: c.user,
pubDate: c.date,
link,
})),
};

View File

@ -1,4 +1,6 @@
const axios = require('../../../utils/axios');
const DateTime = require('luxon').DateTime;
module.exports = (type) => {
const mapping = {
blog: {
@ -22,6 +24,7 @@ module.exports = (type) => {
title: `${article.user.nickname}${article.title}`,
description: article.summary || '',
link: article.url,
pubDate: DateTime.fromMillis(article.timestamp * 1000).toRFC2822(),
})),
};
};

View File

@ -1,5 +1,6 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const Datetime = require('luxon').DateTime;
module.exports = async (ctx) => {
const link = 'http://www.cea.gov.cn/publish/dizhenj/464/479/index.html';
@ -16,12 +17,9 @@ module.exports = async (ctx) => {
ctx.cache.set(url, html, 3 * 24 * 60 * 60);
}
const $1 = cheerio.load(html);
const $content = $1('.detail_main_right_conbg_con > div')
.find('script')
.remove()
.end();
const $content = $1('.detail_main_right_conbg_con > div');
const $container = $('<div>');
$container.append(`<p>${$content.text().replace('', '')}</p>`);
$content
.find('img')
.each((i, el) => {
@ -34,9 +32,32 @@ module.exports = async (ctx) => {
.parent()
.appendTo($container);
const $scriptEls = $content.find('script');
const info = [
$($scriptEls[0]).html().match(/,"(.+)"/)[1],
$($scriptEls[1]).html().match(/"(.+)"/)[1] + ', ',
$($scriptEls[2]).html().match(/"(.+)"/)[1],
$($scriptEls[3]).html().match(/"(.+)"/)[1],
];
const text = info.reduce(
(text, field) => text.replace(/<script>[\s\S]+?<\/script>/, field),
$content.children().not('center').parent().html()
);
$container.prepend(`<p>${text}</p>`);
const dateString = $1('.detail_main_right_conbg_tit')
.children()
.last()
.text()
.trim()
.substring(5);
console.log($container.html());
return {
title: $el.find('a').text(),
link: url,
pubDate: Datetime.fromFormat(dateString, 'yyyy-LL-dd HH:mm:ss').toRFC2822(),
description: $container.html(),
};
})