diff --git a/docs/shopping.md b/docs/shopping.md index 0d7e339e3..4ef0a6e4e 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -415,6 +415,12 @@ For instance, in +## 特斯拉中国 + +### 价格 + + + ## 玩物志 ### 最新 diff --git a/lib/v2/tesla/price/get-price.js b/lib/v2/tesla/price/get-price.js new file mode 100644 index 000000000..6a544ba68 --- /dev/null +++ b/lib/v2/tesla/price/get-price.js @@ -0,0 +1,25 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +async function getTeslaPrice(link) { + const response = await got(link); + + const $ = cheerio.load(response.body); + + let price = ''; + + for (let i = 0; i < $('p').length; i++) { + const $ele = $('p').eq(i); + if ($ele.text().trim().indexOf('经销商报价') > -1) { + const priceDom = $ele.next(); + price = ' => 经销商报价: ' + $(priceDom).text().trim(); + break; + } + } + + return price; +} + +module.exports = { + getTeslaPrice, +}; diff --git a/lib/v2/tesla/price/index.js b/lib/v2/tesla/price/index.js new file mode 100644 index 000000000..a4e33d017 --- /dev/null +++ b/lib/v2/tesla/price/index.js @@ -0,0 +1,41 @@ +const { getTeslaPrice } = require('./get-price'); + +module.exports = async (ctx) => { + const cars = [ + { + name: 'Model 3', + slug: 'model3', + link: 'https://www.dongchedi.com/auto/series/3762', + }, + { + name: 'Model Y', + slug: 'modely', + link: 'https://www.dongchedi.com/auto/series/4363', + }, + { + name: 'Model S', + slug: 'models', + link: 'https://www.dongchedi.com/auto/series/1254', + }, + { + name: 'Model X', + slug: 'modelx', + link: 'https://www.dongchedi.com/auto/series/1255', + }, + ]; + + const promises = cars.map((car) => getTeslaPrice(car.link)); + const prices = await Promise.all(promises); + + ctx.state.data = { + title: 'Tesla Model 系列价格更新', + link: 'https://www.tesla.cn/model3/design#overview', + description: 'Tesla Model 系列价格更新', + item: prices.map((price, index) => ({ + title: `${cars[index].name} 价格更新为 ${price}`, + link: `https://www.tesla.cn/${cars[index].slug}/design#overview`, + author: 'Tesla', + guid: `https://www.tesla.cn/${cars[index].slug}/design#overview#${price}`, + })), + }; +}; diff --git a/lib/v2/tesla/price/maintainer.js b/lib/v2/tesla/price/maintainer.js new file mode 100644 index 000000000..62160fe89 --- /dev/null +++ b/lib/v2/tesla/price/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/price': ['xiaokyo'], +}; diff --git a/lib/v2/tesla/price/radar.js b/lib/v2/tesla/price/radar.js new file mode 100644 index 000000000..29173dcd1 --- /dev/null +++ b/lib/v2/tesla/price/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'tesla.cn': { + _name: '特斯拉中国', + '.': [ + { + title: '价格', + docs: 'https://docs.rsshub.app/shopping.html#te-si-la-zhong-guo', + source: ['/model3/design', '/'], + target: '/tesla/price', + }, + ], + }, +}; diff --git a/lib/v2/tesla/router.js b/lib/v2/tesla/router.js new file mode 100644 index 000000000..d76b305b3 --- /dev/null +++ b/lib/v2/tesla/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/price', require('./price')); +};