-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_verse.py
executable file
·51 lines (42 loc) · 1.55 KB
/
random_verse.py
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
#!/usr/bin/env python3
"""Choose and pretty-print a random verse of scripture."""
# pylint: disable=C0103
import json
import random
import textwrap
file_path = "lds-scriptures.json"
def get_random_verse():
"""Pick a random verse."""
with open(file_path, "r") as scripture_file:
file_list = scripture_file.readlines()
verse_json = random.choice(file_list)
verse = json.loads(verse_json)
return verse
def pretty_print_verse(verse):
"""Given a verse in dictionary form, return a nice-looking string."""
to_return = verse["verse_title"]
to_return += ": \n"
wrapped_verse = textwrap.wrap(verse["scripture_text"])
for line in wrapped_verse:
to_return += line + "\n"
to_return += generate_scripture_url(verse)
return to_return
def generate_scripture_url(verse):
"""Generate a verse's churchofjesuschrist url."""
to_return = "https://www.churchofjesuschrist.org/study/scriptures/"
if verse["volume_lds_url"] == "bm":
to_return += "bofm"
elif verse["volume_lds_url"] == "dc":
to_return += "dc-testament"
else:
to_return += verse["volume_lds_url"]
to_return += "/" + verse["book_lds_url"]
to_return += "/" + str(verse["chapter_number"])
to_return = to_return + "." + str(verse["verse_number"]) + "?lang=eng#"
if verse["verse_number"] == 1:
return to_return + "p1"
return to_return + str(verse["verse_number"] - 1)
if __name__ == "__main__":
rand_verse = get_random_verse()
print("Random verse: ")
print(pretty_print_verse(rand_verse))