Добавлены скрипты для работы с разбитыми на фрагменты СМС
[openhab-process.git] / mqtt-agi / clear-sms-spool
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import sys
5 reload(sys)
6 sys.setdefaultencoding('utf-8')
7
8 from ConfigParser import ConfigParser
9 import paho.mqtt.client as paho
10 from pymessaging.sms import SmsDeliver
11
12 import sqlite3
13 from sqlite3 import Error
14
15 from tempfile import mkstemp
16 from shutil import move
17
18 conffile = sys.argv[1:2]
19
20 config = ConfigParser()
21 config.add_section('sms')
22 # set defaults for anonymous auth
23 config.set('sms', 'tmpfile', '/tmp/sms.db')
24 config.read(conffile)
25
26 sms_db = config.get('sms','tmpfile')
27
28 try:
29   conn = sqlite3.connect(sms_db)
30
31   cur = conn.cursor()
32   cur.execute("select ref from sms_parts group by ref having max(datetime) is null or (julianday('now')-julianday(max(datetime)))>0.005;")
33   refs=cur.fetchall()
34   for ref in refs:
35     cur.execute("select text from sms_parts where ref=%s order by seq" % (ref))
36     full_text=''.join(rec[0] for rec in cur.fetchall()).replace("\"","")
37     f,path=mkstemp(suffix=".call")
38     f=open(path,"w")
39     f.write("Application: Dial\n")
40     f.write("Channel: Local/smsraw@DID_mobile\n")
41     f.write("Context: smsraw\n")
42     f.write("Setvar: SMS_FULL_TEXT=%s" % full_text)
43     f.close()
44     move(path,'/var/spool/asterisk/outgoing')
45     cur.execute("delete from sms_parts where ref=%s" % (ref))
46     conn.commit()
47
48 except:
49   None