This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strava.sh
164 lines (132 loc) · 3.24 KB
/
strava.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# -----------------------------------------------------------------------------
# Info:
# author: Santhosh Veer
# file: strava.sh
# created: 30.08.2022
# revision: 30.08.2022
# version: 0.1
# -----------------------------------------------------------------------------
#
# Bash Shell Script to Upload GPX file on your Strava Profile Activity
#
# DOCS - https://developers.strava.com/docs/uploads/
# Create Strava API Account - https://developers.strava.com/docs/getting-started/#account
# Reference - https://gist.github.com/michaellihs/bb262e2c6ee93093485361de282c242d
#
# -----------------------------------------------------------------------------
# Load ENV Variables
. .env
# Version Info
VERSION=0.1
## File name
SCRIPTNAME=$(basename "$0")
# Strava API key
ACCESSKEY=$ACCESSKEY
# Get Activity Status
get_status(){
echo -e "\\n"
echo -e "\\033[1;32m Get Activity Post Status \\033[0m"
echo -e "\\n"
echo -n "Enter the Activity ID: "
read -r activityid
echo -e "\\n"
# If no Inputs you will see this Alert message
if [[ ! $activityid ]]; then
echo -e "\\033[1;31m Error: Activity ID Missing \\033[0m \\n"
exit 1
fi
# Curl request
curl https://www.strava.com/api/v3/uploads/$activityid -H "Authorization: Bearer $ACCESSKEY"
echo -e "\\n"
}
# Upload GPX File to Strava
upload_gpx(){
echo -e "\\n"
echo -e "\\033[1;32m == Upload GPX File to Strava == \\033[0m"
echo -e "\\n"
echo -n "Enter your Activity Type (Run or Walk or Ride): "
read -r ridetype
echo -n "Enter GPX File Name: "
read -r filename
echo -e "\\n"
# If no Inputs you will see this Alert message
if [[ ! $ridetype ]]; then
echo -e "\\033[1;31m Error: Ride Type Missing \\033[0m \\n"
exit 1
fi
if [[ ! $filename ]]; then
echo -e "\\033[1;31m Error: File name is Missing \\033[0m \\n"
exit 1
fi
# Curl request
curl -X POST https://www.strava.com/api/v3/uploads \
-H "Authorization: Bearer $ACCESSKEY" \
-F activity_type=$ridetype \
-F name="🔘 Activity Posted via CLI ☑" \
-F description="#⃣ This Activity Upload via GPX File #⃣" \
-F data_type="gpx" \
-F file=$DIRLOC/$filename.gpx
}
# Help Message
help(){
echo -e "\\n"
echo -e "$SCRIPTNAME [options]
Example:
strava.sh -l
Options:
-l Get Upload Status
-s Upload GPX File to Strava
-h Display Help Message
-v Check CLI Version
\\n"
}
# No input params triggers this error
check_for_empty_input(){
if [ $# -eq 0 ];
then
echo -e "\\n"
echo -e "\\033[1;31m Error: No input \\033[0m \\n"
help
exit 1
fi
}
# Check for required packages
check_requirements(){
local requirements=("$@")
for app in "${requirements[@]}"; do
type "$app" >/dev/null 2>&1 || \
{ echo >&2 "$app is required but it's not installed. Aborting."; exit 1; }
done
}
# Main Functions
main(){
check_for_empty_input "$@"
check_requirements jq curl
while getopts ':lsvh' flag; do
case "$flag" in
l)
get_status
;;
s)
upload_gpx
;;
v)
echo -e "\\033[1;32m Version $VERSION \\033[0m"
exit 0
;;
h)
help
exit 0
;;
?)
echo "script usage: $SCRIPTNAME [-l] [-s] [-v] [-h]" >&2
exit 1
;;
*)
esac
done
shift $((OPTIND-1))
}
main "$@"
exit 0