diff --git a/docs/README.md b/docs/README.md index dae0e1b431..826f3e4789 100644 --- a/docs/README.md +++ b/docs/README.md @@ -530,6 +530,16 @@ RSSHub 提供下列 API 接口: +### 龙腾网 + + + +| 最新 | 每周 | 每月 | 全年 | +| ---- | ---- | ----- | ---- | +| (空) | week | month | year | + + + ## 编程 ### 掘金 diff --git a/router.js b/router.js index 077a56e799..bf4ac4077a 100644 --- a/router.js +++ b/router.js @@ -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')); diff --git a/routes/ltaaa/_article.js b/routes/ltaaa/_article.js new file mode 100644 index 0000000000..7cf5247d64 --- /dev/null +++ b/routes/ltaaa/_article.js @@ -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() + '


' + $('div.post-comment').html(); + + const item = { + title: title, + pubDate: date.toUTCString(), + author: author, + link: url, + description: content, + }; + return item; +}; diff --git a/routes/ltaaa/main.js b/routes/ltaaa/main.js new file mode 100644 index 0000000000..3e0541adc2 --- /dev/null +++ b/routes/ltaaa/main.js @@ -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, + }; +};