-
Notifications
You must be signed in to change notification settings - Fork 0
/
talking.py
54 lines (42 loc) · 1.07 KB
/
talking.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
import os
import sqlite3 as lite
import sys
import ConfigParser
import time
import re
from daemon import Daemon
class TalkingDaemon(Daemon):
def __init__(self,pid):
super(TalkingDaemon,self).__init__(pid)
self.running = True
self.con = lite.connect('/tmp/speakbot.db')
def run(self):
while self.running:
time.sleep(1)
cur = self.con.cursor()
cur.execute("select id,handle,channel,message from talk limit 1")
rows = cur.fetchall()
for row in rows:
#print row
speak = re.sub(r'[^\w]', ' ', row[3])
print row
cmd = 'espeak -s 130 "%s"'% speak
print cmd
cur.execute("delete from talk where id = ?",(row[0],))
self.con.commit()
if __name__ == "__main__":
daemon = TalkingDaemon('/tmp/speakbot_talking_deamon.pid')
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print "Unknown command"
sys.exit(2)
sys.exit(0)
else:
print "usage: %s start|stop|restart" % sys.argv[0]
sys.exit(2)