feat: add 公众号Telegrame 频道来源 (#2205)

* feat: add 公众号Telegrame 频道来源

* 去掉全文抓取
This commit is contained in:
Chenyang Shi
2019-05-22 22:46:53 +08:00
committed by DIYgod
parent 77c9450311
commit 09e331988a
3 changed files with 49 additions and 0 deletions

View File

@@ -646,6 +646,16 @@ pageClass: routes
<Route author="HenryQW" example="/wechat/csm/huxiu_com" path="/wechat/csm/:id" :paramsDesc="['公众号 id, 打开公众号页, 在 URL 中找到 id']"/> <Route author="HenryQW" example="/wechat/csm/huxiu_com" path="/wechat/csm/:id" :paramsDesc="['公众号 id, 打开公众号页, 在 URL 中找到 id']"/>
### 公众号Telegrame 频道来源)
<Route author="LogicJake" example="/wechat/tgchannel/lifeweek" path="/wechat/tgchannel/:id" :paramsDesc="['公众号绑定频道 id']">
::: warning 注意
该方法需要通过 efb 进行频道绑定,具体操作见[https://github.com/DIYgod/RSSHub/issues/2172](https://github.com/DIYgod/RSSHub/issues/2172)
:::
</Route>
### 公众平台系统公告栏目 ### 公众平台系统公告栏目
<Route author="xyqfer" example="/wechat/announce" path="/wechat/announce" /> <Route author="xyqfer" example="/wechat/announce" path="/wechat/announce" />

View File

@@ -445,6 +445,7 @@ router.get('/wechat/wemp/:id', require('./routes/tencent/wechat/wemp'));
router.get('/wechat/csm/:id', require('./routes/tencent/wechat/csm')); router.get('/wechat/csm/:id', require('./routes/tencent/wechat/csm'));
router.get('/wechat/announce', require('./routes/tencent/wechat/announce')); router.get('/wechat/announce', require('./routes/tencent/wechat/announce'));
router.get('/wechat/miniprogram/plugins', require('./routes/tencent/wechat/miniprogram/plugins')); router.get('/wechat/miniprogram/plugins', require('./routes/tencent/wechat/miniprogram/plugins'));
router.get('/wechat/tgchannel/:id', require('./routes/tencent/wechat/tgchannel'));
// All the Flight Deals // All the Flight Deals
router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index')); router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index'));

View File

@@ -0,0 +1,38 @@
const axios = require('@/utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const { data } = await axios.get(`https://t.me/s/${id}`);
const $ = cheerio.load(data);
const list = $('.tgme_widget_message_wrap');
const out = await Promise.all(
list
.map((index, item) => {
item = $(item);
const title = item.find('.tgme_widget_message_text > a:nth-child(2)').text();
const link = item.find('.tgme_widget_message_text > a:nth-child(2)').attr('href');
const pubDate = new Date(item.find('.tgme_widget_message_date time').attr('datetime')).toUTCString();
const description = item.find('.tgme_widget_message_text').html();
const single = {
title,
pubDate,
link,
description,
};
return single;
})
.get()
);
out.reverse();
ctx.state.data = {
title: $('.tgme_channel_info_header_title').text(),
link: `https://t.me/s/${id}`,
item: out,
};
};