-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgenerate-options-codes.sh
executable file
·91 lines (71 loc) · 2.63 KB
/
generate-options-codes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# This script requires jq and pup
# Constants
export readonly MODEL_S_DESIGN_URL="https://www.tesla.com/models/design"
export readonly MODELS_OPTIONS_FILE="models-options.md"
export readonly MODELS_TITLE="Model S Options"
export readonly MODEL_X_DESIGN_URL="https://www.tesla.com/modelx/design"
export readonly MODELX_OPTIONS_FILE="modelx-options.md"
export readonly MODELX_TITLE="Model X Options"
export readonly TEMP_FILE="temp.html"
###############################################################################
# Create options markdown for vehicle type
# Arguments:
# ${1} - the design url to pull options from
# ${2} - the markdown file output that will be written in the options dir
# Returns:
# None
###############################################################################
get_options() {
if [ -z "${1}" ]; then
echo "No Design URL"
exit 0
fi
if [ -z "${2}" ]; then
echo "No Output File"
exit 0
fi
if [ -z "${3}" ]; then
echo "No Title"
exit 0
fi
designURL="${1}"
optionsFile="${2}"
title="${3}"
pushd .. 2>/dev/null
pushd codes 2>/dev/null
wget -q ${designURL} -O ${TEMP_FILE} >/dev/null 2>/dev/null
DESIGN_URLS=`cat ${TEMP_FILE} | pup 'link[hreflang] attr{href}'`
echo "# ${title}" > ${optionsFile}
echo $'\n' >> ${optionsFile}
echo $'{% hint style="danger" %}' >> ${optionsFile}
echo $'Do **not** manually edit this document. It is programmatically generated by [generate-options-codes.sh](https://github.com/joeblau/teslaapi.io/blob/master/.travis/generate-options-codes.sh).' >> ${optionsFile}
echo $'{% endhint %}\n' >> ${optionsFile}
for DESIGN_URL in $DESIGN_URLS
do
wget -q $DESIGN_URL -O ${TEMP_FILE} >/dev/null 2>/dev/null
JQUERY=`grep "jQuery.extend" ${TEMP_FILE}`
SIZE=`expr ${#JQUERY} - 33`
JSON_STRING=`echo ${JQUERY:31:${SIZE}}`
echo $"### ${DESIGN_URL}" >> ${optionsFile}
echo $'\n' >> ${optionsFile}
echo $'```javascript' >> ${optionsFile}
echo $JSON_STRING | jq '.tesla.configSetPrices | fromjson.options | with_entries(.value |= .long_name) | del(.[] | nulls)' >> ${optionsFile}
echo $'\n```\n\n' >> ${optionsFile}
done
rm ${TEMP_FILE}
popd 2>/dev/null
popd 2>/dev/null
}
###############################################################################
# Generates option code lists for the Model S and Model X
# Arguments:
# None
# Returns:
# None
###############################################################################
main() {
get_options "${MODEL_S_DESIGN_URL}" "${MODELS_OPTIONS_FILE}" "${MODELS_TITLE}"
get_options "${MODEL_X_DESIGN_URL}" "${MODELX_OPTIONS_FILE}" "${MODELX_TITLE}"
}
main