forked from prathimacode-hub/Awesome_Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoem_automation.py
31 lines (23 loc) · 888 Bytes
/
poem_automation.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
# first install poetpy library using pip install poetpy then import it
# import poetpy library
import poetpy
import random
# import random, using random to select a random poem
try:
print('Poem of which author you want to listen?')
# taking the author name as input
auth = input()
# using the get_poetry() function to get poems
poem = poetpy.get_poetry('author', auth, 'title,linecount')
poems = poetpy.get_poetry('author', auth, 'lines')
poem_len = len(poem)
# selecting a random poem from the list of poems
poem_no = random.randint(1, poem_len)
# printing the different values realted to poem
print("Title- ", poem[poem_no]['title'])
print("No. of lines-", poem[poem_no]['linecount'])
# print the peom
poem_str = '\n'
print("Poem-\n", poem_str.join(poems[poem_no]['lines']))
except Exception as e:
pass