-
Notifications
You must be signed in to change notification settings - Fork 0
/
newrwxboostpage
executable file
·66 lines (58 loc) · 2.2 KB
/
newrwxboostpage
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
#!/bin/sh
Help()
{
# Display Help
echo "Add description of the script functions here."
echo
echo "Syntax: scriptTemplate [-d|h|v|V]"
echo "options:"
echo "d select day to grab notes for."
echo "h Print this Help."
echo "v Verbose mode."
echo "V Print software version and exit."
echo
}
get_day_summary()
{
raw_url="https://raw.githubusercontent.com/rwxrob/boost/old-20210722/README.md"
normal_url="https://github.com/rwxrob/boost/blob/old-20210722/README.md"
source_readme=$(curl -s "${raw_url}")
# okay, sooo the below works, but takes an insane amount of time. why?
# it's slow because for each match, the string length is counted multiple times
# parameter expansion has a known issue of having quadratic complexity (yike)
# https://stackoverflow.com/questions/14967299/parameter-expansion-slow-for-large-data-sets
# so we're going back to the original sed way of doing it which is speedy-weedy :)
# day_summary_interm="${source_readme##*##*day"$day"}"
# day_summary="${day_summary_interm%%##*}"
day_summary=$(echo "${source_readme}" | sed -n '/Day '"${day}"'/,/##/p')
# day_title=`echo "$day_summary" | grep -m 1 ":" | sed 's/^.*: //'`
# here we have successfully replaced one sed statement with parameter expansion!
# go me!
line_1=$(echo "${day_summary}" | grep -m 1 ":")
day_title="${line_1#*: }"
day_title_url=$(echo "${day_title}" | tr ' ' '-')
day_title_url=$(echo "${day_title_url}" | tr -d '/(),')
day_title_url=$(echo "${day_title_url}" | tr '[:upper:]' '[:lower:]')
video_link=$(echo "${day_summary}" | grep -m 1 -o 'https://youtu.be.*)$' | sed 's/)$//')
materials_link="${normal_url}#-beginner-boost-day-${day}-${day_title_url}"
}
# Get cli options
while getopts ":hd:" option; do
case ${option} in
h) # display Help
Help
exit;;
d) # enter day to grab summary for
day=${OPTARG};;
\?) # invalid option
echo "Error: invalid option"
exit;;
*) # another invalid option
echo "Error: invalid option"
exit;;
esac
done
# shellcheck source=./exports
. ./exports
get_day_summary
node newrwxboostpage.js "👩🏼💻 rwx boost day " "${day} - ${day_title}" "${video_link}" "${materials_link}"