feat(route): 特斯拉价格 (#10507)

* feat: 特斯拉价格

* fix: missing docs

* fix: url
This commit is contained in:
xiaokyo 2022-09-04 00:16:57 +08:00 committed by GitHub
parent f29094db96
commit cde7722bee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 0 deletions

View File

@ -415,6 +415,12 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa
</Route>
## 特斯拉中国
### 价格
<Route author="xiaokyo" example="/tesla/price" path="/tesla/price" radar="1"/>
## 玩物志
### 最新

View File

@ -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,
};

View File

@ -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}`,
})),
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/price': ['xiaokyo'],
};

View File

@ -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',
},
],
},
};

3
lib/v2/tesla/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/price', require('./price'));
};