-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbible_verse
More file actions
executable file
·96 lines (87 loc) · 3.12 KB
/
bible_verse
File metadata and controls
executable file
·96 lines (87 loc) · 3.12 KB
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
#!/bin/sh
# Help menu
if [ "$1" = "-h" -o "$1" = "--help" ]; then
echo "Usage: ./bible_verse book_name chapter verse [version]
./bible_verse --keyword/-k [keyword] [version]
"
echo "Example:
./bible_verse John 3 16 KJV (ESV by default)
./bible_verse John 3 16-21 KJV
"
echo "Keyword search examples:
./bible_verse -k Mary (NIV by default)
./bible_verse -k 'Jesus said' DRA
./bible_verse -k εὐλογία SBLGNT
./bible_verse -k Christus VULGATE
"
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 [ "$1" = "-k" -o "$1" = "--keyword" ]; then
if [ $# -lt 2 ]; then
echo "Error: Incorrect number of arguments."
exit 1
fi
# a more standard modern version to fit common english keywords
version="NIV"
if [ $# -eq 3 ]; then
version=$3
fi
search=$(echo "$2" | sed 's/\s\+/+/g')
# currently max 100 output to not clutter terminal
keyword_search=$(curl -s "https://www.biblegateway.com/quicksearch/?qs_version="$version"&quicksearch="$search"&resultspp=100")
version_split=""$version"\">|</a>"
search_result_list=$(echo "$keyword_search" | sed -zEn 's/.*search-result-list">(.*)/\1/p')
text=$(echo "$search_result_list" | awk -v ver="$version_split" -F'<div class="bible-item-title-wrap col-sm-3">|<div class="bible-item-extras">' '
NF > 1 {
split($2, title_part, ver);
title = title_part[2];
verse = $1;
printf "%s\n%s ", verse, title;
}' | sed 's/In Context//g; s/<[^>]*>//g; s/^[ \t]*//; /^$/d; G')
printf "%s\n" "$text"
exit 0
fi
if [ $# -lt 3 ]; then
echo "Error: Incorrect number of arguments."
exit 1
fi
# Initial variables
version="DRA"
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"