diff --git a/docs/other.md b/docs/other.md index b6727667c..b2211dfa0 100644 --- a/docs/other.md +++ b/docs/other.md @@ -717,6 +717,22 @@ type 为 all 时,category 参数不支持 cost 和 free +## 汽油价格网 + +### 今日油价查询 + + + +::: tip 提示 + +路径处填写对应页面 URL 中 `http://www.qiyoujiage.com/` 和 `.shtml` 之间的字段。下面是一个例子。 + +若订阅 [福建漳州龙海今日油价](http://www.qiyoujiage.com/fujian/zhangzhou/longhai.shtml) 则将对应页面 URL 中 `http://www.qiyoujiage.com/` 和 `.shtml` 之间的字段 `fujian/zhangzhou/longhai` 作为路径填入。此时路由为 [`/qiyoujiage/fujian/zhangzhou/longhai`](https://rsshub.app/qiyoujiage/fujian/zhangzhou/longhai) + +::: + + + ## 且听风吟福利 ### 分类 @@ -925,12 +941,6 @@ type 为 all 时,category 参数不支持 cost 和 free -## 油价 - -### 今日油价 - - - ## 有据 ### 最新文章列表 diff --git a/lib/router.js b/lib/router.js index e87e376a1..7ed0478e4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -928,9 +928,6 @@ router.get('/chouti/:subject?', lazyloadRouteHandler('./routes/chouti')); // Westore router.get('/westore/new', lazyloadRouteHandler('./routes/westore/new')); -// 油价 -router.get('/oilprice/:area', lazyloadRouteHandler('./routes/oilprice')); - // nHentai router.get('/nhentai/search/:keyword/:mode?', lazyloadRouteHandler('./routes/nhentai/search')); router.get('/nhentai/:key/:keyword/:mode?', lazyloadRouteHandler('./routes/nhentai/other')); diff --git a/lib/routes/oilprice/index.js b/lib/routes/oilprice/index.js deleted file mode 100644 index 1c7dd586a..000000000 --- a/lib/routes/oilprice/index.js +++ /dev/null @@ -1,66 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const iconv = require('iconv-lite'); - -module.exports = async (ctx) => { - const { area } = ctx.params; - const link = 'http://oil.usd-cny.com/'; - const response = await got({ - method: 'get', - url: link, - responseType: 'buffer', - }); - const $ = cheerio.load(iconv.decode(response.data, 'gb2312')); - const $list = $('.content').eq(0).find('table tbody tr'); - const resultItem = []; - let areaName = ''; - const updateTime = $('.time').text().split(':')[1]; - const labelList = $list - .eq(1) - .find('td') - .slice(1) - .map((index, item) => $(item).text()) - .get(); - - for (let i = 2; i < $list.length; i++) { - if ($list.eq(i).find('td a').attr('href').includes(`oil.usd-cny.com/${area}.htm`)) { - const $item = $list.eq(i); - areaName = $item.find('td a').text(); - const { description, content } = labelList.reduce( - (descObj, label, index) => { - const price = $item - .find('td') - .eq(index + 1) - .text(); - - descObj.description += ` - ${label}: ${price}
- `; - descObj.content += `${label}-${price}; `; - - return descObj; - }, - { - description: '', - content: '', - } - ); - - resultItem.push({ - title: `${updateTime}-${areaName}油价: ${content}`, - description, - link, - guid: updateTime, - pubDate: new Date(updateTime).toUTCString(), - }); - break; - } - } - - ctx.state.data = { - title: `今日油价查询-${areaName}`, - description: '今日汽油价格查询 最新柴油油价实时行情', - link, - item: resultItem, - }; -}; diff --git a/lib/v2/qiyoujiage/maintainer.js b/lib/v2/qiyoujiage/maintainer.js new file mode 100644 index 000000000..e14a130df --- /dev/null +++ b/lib/v2/qiyoujiage/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:path+': ['TonyRL'], +}; diff --git a/lib/v2/qiyoujiage/price.js b/lib/v2/qiyoujiage/price.js new file mode 100644 index 000000000..b2926700f --- /dev/null +++ b/lib/v2/qiyoujiage/price.js @@ -0,0 +1,28 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const md5 = require('@/utils/md5'); + +module.exports = async (ctx) => { + const { path } = ctx.params; + const link = `http://www.qiyoujiage.com/${path}.shtml`; + + const { data: response } = await got(link); + const $ = cheerio.load(response); + + const priceText = $('#youjia').text(); + const item = [ + { + title: priceText, + description: $('#youjia').html(), + link, + guid: `${link}#${md5(priceText)}`, + }, + ]; + + ctx.state.data = { + title: $('title').text(), + description: $('meta[name="Description"]').attr('content'), + link, + item, + }; +}; diff --git a/lib/v2/qiyoujiage/radar.js b/lib/v2/qiyoujiage/radar.js new file mode 100644 index 000000000..c29822e00 --- /dev/null +++ b/lib/v2/qiyoujiage/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'qiyoujiage.com': { + _name: '汽油价格网', + '.': [ + { + title: '今日油价查询', + docs: 'https://docs.rsshub.app/other.html#qi-you-jia-ge-wang', + source: ['/*'], + target: (_, url) => `/qiyoujiage${new URL(url).pathname.replace('.shtml', '')}`, + }, + ], + }, +}; diff --git a/lib/v2/qiyoujiage/router.js b/lib/v2/qiyoujiage/router.js new file mode 100644 index 000000000..365a01c2f --- /dev/null +++ b/lib/v2/qiyoujiage/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:path+', require('./price')); +};