-
Notifications
You must be signed in to change notification settings - Fork 0
/
reaction.py
40 lines (31 loc) · 1.02 KB
/
reaction.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
# Reaction
import wikipedia
import random
wikipedia.set_lang('es')
with open('./data/rtas.txt', 'r') as f:
rtas = f.read().splitlines()
def smartass(message):
# change to for loop with try
try:
rta = wikipedia.summary(message, sentences=2, auto_suggest=True,
redirect=False).replace('\u200b','')
if len(rta) > 500: # If msg too long, send first Paragraph
rta = rta.partition('\n')[0]
return rta
except Exception as e:
print(e)
print('no spanish')
wikipedia.set_lang('en')
# It won't reach this place unless exception (otherwise returns)
try:
rta = wikipedia.summary(message, sentences=2, auto_suggest=True,
redirect=False).replace('\u200b','')
if len(rta) > 500:
rta = rta.partition('\n')[0]
except Exception as e:
print(e)
print('no english')
rta = random.choice(rtas)
finally:
wikipedia.set_lang('es')
return rta