tesla-inventory 1.7.21 → 1.7.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### 1.7.25 (2021-10-23)
6
+
7
+ ### 1.7.24 (2021-10-23)
8
+
9
+ ### 1.7.23 (2021-10-16)
10
+
11
+ ### 1.7.22 (2021-10-11)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * script ([9446b8c](https://github.com/teslahunt/tesla-inventory/commit/9446b8c109eb13ec1492a715611abc93d84bd806))
17
+
5
18
  ### 1.7.21 (2021-10-11)
6
19
 
7
20
  ### 1.7.20 (2021-10-11)
package/codes.json CHANGED
@@ -281,6 +281,7 @@
281
281
  "MT317": "Long Range All-Wheel Drive Performance",
282
282
  "MT320": "Standard Range Plus Rear-Wheel Drive",
283
283
  "MT321": "Long Range All-Wheel Drive",
284
+ "MT322": "Standard Range Plus Rear-Wheel Drive",
284
285
  "MT336": "Standard Range Plus Rear-Wheel Drive",
285
286
  "MT337": "Standard Range Plus Rear-Wheel Drive",
286
287
  "MTS01": "Standard Range",
@@ -348,7 +349,7 @@
348
349
  "PT01": "Trunk Power trunk",
349
350
  "PX00": "No Performance Plus Package",
350
351
  "PX01": "Performance Plus",
351
- "PX4D": "90 kWh Performance",
352
+ "PX4D": " 90 kWh Performance",
352
353
  "PX6D": "Zero to 60 in 2.5 sec",
353
354
  "QLBS": "Black Premium Interior",
354
355
  "QLFC": "Cream Premium Interior",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "tesla-inventory",
3
3
  "description": "Retrieve real-time data from Tesla Inventory.",
4
4
  "homepage": "https://nicedoc.io/Kikobeats/tesla-inventory",
5
- "version": "1.7.21",
5
+ "version": "1.7.25",
6
6
  "main": "index.js",
7
7
  "author": {
8
8
  "email": "josefrancisco.verdu@gmail.com",
@@ -23,16 +23,17 @@
23
23
  "MT301": 1990,
24
24
  "MT302": 11100,
25
25
  "MT303": 8000,
26
- "MT304": 10520,
26
+ "MT304": 8880,
27
27
  "MT308": 820,
28
28
  "MT310": 8000,
29
29
  "MT311": 8880,
30
30
  "MT314": 2590,
31
31
  "MT315": 8990,
32
32
  "MT316": 8990,
33
- "MT317": 10520,
33
+ "MT317": 8880,
34
34
  "MT320": 4990,
35
35
  "MT321": 8990,
36
+ "MT322": 2590,
36
37
  "MT336": 1880,
37
38
  "MT337": 2590,
38
39
  "MTS03": 5000,
package/scripts/codes.js CHANGED
@@ -19,26 +19,29 @@ const main = async () => {
19
19
 
20
20
  const $ = cheerio.load(body)
21
21
 
22
- const table = $('tbody')
22
+ const selector = $(
23
+ '#root > div > div > div > div > div > div > div > div > div > div > div > div > div > div > div > div > div > div > div > div > div'
24
+ )
23
25
 
24
- const [, ...codes] = table
25
- .find('tr td:nth-child(1)')
26
- .map(function () {
27
- return $(this).text()
28
- })
29
- .get()
26
+ const codes = selector.children()
30
27
 
31
- const [, ...titles] = table
32
- .find('tr td:nth-child(2)')
33
- .map(function () {
34
- return $(this).text()
28
+ const optionCodes = codes
29
+ .map(function (index) {
30
+ if (index === 0) return null
31
+ const el = $(this)
32
+ const base = el.children()
33
+ const code = base.children('div div:nth-child(1)').text()
34
+ const title = base.children('div div:nth-child(2)').text()
35
+ return { code, title }
35
36
  })
36
37
  .get()
38
+ .reduce((acc, { code, title }) => ({ ...acc, [code]: title }), {})
37
39
 
38
- const optionCodes = codes.reduce(
39
- (acc, code, index) => ({ ...acc, [code]: titles[index] }),
40
- {}
41
- )
40
+ if (Object.keys(optionCodes).length === 0) {
41
+ throw new Error(
42
+ 'The target website has changed, selectors need to be rework.'
43
+ )
44
+ }
42
45
 
43
46
  jsonFuture.save('codes.json', sortObjectByKey(optionCodes))
44
47
  }