-
Notifications
You must be signed in to change notification settings - Fork 0
/
bible_verse
executable file
·58 lines (52 loc) · 1.77 KB
/
bible_verse
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
#!/bin/sh
# Help menu
if [ "$1" = "-h" -o "$1" = "--help" ]; then
echo "Usage: ./bible_verse book_name chapter verse [version]"
echo "Example:
./bible_verse John 3 16 KJV (ESV by default)
./bible_verse John 3 16-21 KJV"
echo "For books with numbers infront of them, ex: 1 Peter
./bible_verse 1Peter 1 1-2 SBLGNT"
echo "For output to image
./bible_verse John 3 16 KJV | python3 verseonimage.py
./bible_verse John 3 16-21 KJV | python3 verseonimage.py
./bible_verse John 3 16-21 NKJV | python3 versetoimage.py <your image.png>"
exit 0
fi
if [ $# -lt 3 ]; then
echo "Error: Incorrect number of arguments."
exit 1
fi
# Initial variables
version="ESV"
verse_range=$(printf "%s" "$3" | grep -oE "[0-9]+-[0-9]+")
verse_result=
# Use as version if version argument exist
if [ $# -eq 4 ]; then
version=$4
fi
# Prints book name,chapter,verse,and version
printf "%s\n" "$1 $2 $3 $version"
# Request to biblegateway and parse response
request_and_parse(){
bible=$(curl -s "https://www.biblegateway.com/passage/?search=$1+$2:$3&version=$4")
verse_text=$(printf "%s" "$bible" | sed -n 's/.*<meta property="og:description" content="\(.*\)".*/\1/p')
verse_result="${verse_result} ${verse_text}"
}
# Checks and adjustments for a certain scraping block
if [ -n "$verse_range" ]; then
number1=$(printf "%s" "$verse_range" | cut -d'-' -f1)
number2=$(printf "%s" "$verse_range" | cut -d'-' -f2)
range_count=$((number2 - number1))
if [ $range_count -ge 5 ]; then
request_and_parse "$1" "$2" "$number1-$((number1+4))" "$version"
while [ $((number1+5)) -le $number2 ]; do
number1=$((number1+5))
request_and_parse "$1" "$2" "$number1-$number2" "$version"
done
printf "%s\n" "$verse_result"
exit 0
fi
fi
request_and_parse "$1" "$2" "$3" "$version"
printf "%s\n" "$verse_result"