diff --git a/docs/social-media.md b/docs/social-media.md index f2c468e630..55c0eef926 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -646,6 +646,16 @@ pageClass: routes +### 公众号(Telegrame 频道来源) + + + +::: warning 注意 + +该方法需要通过 efb 进行频道绑定,具体操作见[https://github.com/DIYgod/RSSHub/issues/2172](https://github.com/DIYgod/RSSHub/issues/2172) +::: + + ### 公众平台系统公告栏目 diff --git a/lib/router.js b/lib/router.js index 23da5298b1..94cd769ea7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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/announce', require('./routes/tencent/wechat/announce')); 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 router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index')); diff --git a/lib/routes/tencent/wechat/tgchannel.js b/lib/routes/tencent/wechat/tgchannel.js new file mode 100644 index 0000000000..ae0ee27b64 --- /dev/null +++ b/lib/routes/tencent/wechat/tgchannel.js @@ -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, + }; +};