add feed for [ltaaa.com] (#1014)

This commit is contained in:
sgqy
2018-10-31 11:02:10 +08:00
committed by DIYgod
parent 7e8d66eacd
commit 94b0f45a8a
4 changed files with 112 additions and 0 deletions

View File

@@ -530,6 +530,16 @@ RSSHub 提供下列 API 接口:
<route name="基金净值更新" author="HenryQW" example="/xueqiu/fund/040008" path="/xueqiu/fund/:id" :paramsDesc="['基金代码, 可在基金主页 URL 中找到. 此路由的数据为场外基金 (`F`开头)']"/>
### 龙腾网
<route name="转译网贴" author="sgqy" example="/ltaaa" path="/ltaaa/:type?" :paramsDesc="['热门类型.']">
| 最新 | 每周 | 每月 | 全年 |
| ---- | ---- | ----- | ---- |
| (空) | week | month | year |
</route>
## 编程
### 掘金

View File

@@ -718,6 +718,9 @@ router.get('/oilprice/:area', require('./routes/oilprice'));
router.get('/nhentai/search/:keyword', require('./routes/nhentai/search'));
router.get('/nhentai/:key/:keyword', require('./routes/nhentai/other'));
// 龙腾网
router.get('/ltaaa/:type?', require('./routes/ltaaa/main'));
// AcFun
router.get('/acfun/bangumi/:id', require('./routes/acfun/bangumi'));

41
routes/ltaaa/_article.js Normal file
View File

@@ -0,0 +1,41 @@
const axios = require('../../utils/axios'); // get web content
const cheerio = require('cheerio'); // html parser
const iconv = require('iconv-lite');
const domain = 'http://www.ltaaa.com';
module.exports = async function get_article(url) {
if (/^\/.*$/.test(url)) {
url = domain + url;
}
const response = await axios({
method: 'get',
url: url,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0',
responseType: 'arraybuffer',
});
const data = response.data;
const $ = cheerio.load(iconv.decode(data, 'CP936'));
const title = $('div.post-title > strong').text();
const author = $('div.post-param > a').text();
const pub_date_raw = $('div.post-param')
.clone()
.children()
.remove()
.end()
.text();
let date = new Date(pub_date_raw);
date.setHours(date.getHours() - 8);
date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
const content = $('div.post-content').html() + '<br/><hr/><br/>' + $('div.post-comment').html();
const item = {
title: title,
pubDate: date.toUTCString(),
author: author,
link: url,
description: content,
};
return item;
};

58
routes/ltaaa/main.js Normal file
View File

@@ -0,0 +1,58 @@
// Warning: The author still knows nothing about javascript!
// params:
// type: notification type
const axios = require('../../utils/axios'); // get web content
const cheerio = require('cheerio'); // html parser
const get_article = require('./_article');
const base_url = 'http://www.ltaaa.com';
module.exports = async (ctx) => {
const type = ctx.params.type || 'news'; // week, month or year
let target = '';
switch (type) {
case 'week':
target = 'ul.vweek';
break;
case 'month':
target = 'ul.vmonth';
break;
case 'year':
target = 'ul.vyear';
break;
default:
target = 'ul.wlist';
}
const list_url = base_url + '/wtfy.html';
const response = await axios({
method: 'get',
url: list_url,
});
const data = response.data; // content is html format
const $ = cheerio.load(data);
// get urls
const detail_urls = [];
let a = $(target).find('a.rtitle');
if (!a || a.length <= 0) {
a = $(target).find('div.dtop > a');
}
for (let i = 0; i < a.length; ++i) {
const tmp = $(a[i]).attr('href');
detail_urls.push(tmp);
}
// get articles
const article_list = await Promise.all(detail_urls.map((url) => get_article(url)));
// feed the data
ctx.state.data = {
title: '龙腾网转译网贴',
link: list_url,
item: article_list,
};
};