/
responseGen.py
executable file
·72 lines (55 loc) · 1.63 KB
/
responseGen.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
import cleverbot
import sys
import string
import serial
import time
from functools import wraps
import errno
import os
import signal
import requests
from timeout import timeout
def mainFunction():
qu = sys.argv[1]
print "Query: " + qu
user = "Yolo!"
if(qu == "-1"):
response = "&"
elif(qu == "-2"):
response = "+&"
else:
cb1 = cleverbot.Cleverbot()
response = cb1.ask(qu)
print "Response: " + response
#Replace all punctuation with blanks
for c in string.punctuation:
response = response.replace(c, "")
while (response.find("app") != -1 or response.find("clever") != -1 or response.find("bot") != -1 or response.find("com") != -1):
response = cb1.ask(qu)
respon = response.strip()
#Make all spaces periods
response = response.replace(" ", ".").strip()
response = response.lower() + "&"
username = sys.argv[2]
if username == "None":
pass
elif response != "&":
if response == "+&":
respo = "Yo"
que = "Yo"
else:
respo = respon
que = qu
user = username
conversation = str(user) + " said: " + str(que) + " <br>" + "Bot responded: " + str(respo) + " <br><hr>"
requestURL = "http://www.purduecs.com/write.php?username=" + str(user) + "&conversation=" + str(conversation)
r = requests.get(requestURL)
return response
response = mainFunction()
print response
ser = serial.Serial('/dev/ttyACM0', 57600)
time.sleep(3)
ser.write(response)
#while True:
#print ser.readline()