2 # -*- coding: utf-8 -*-
6 sys.setdefaultencoding('utf-8')
8 from ConfigParser import ConfigParser
9 import paho.mqtt.client as paho
10 from pymessaging.sms import SmsDeliver
13 from sqlite3 import Error
15 from tempfile import mkstemp
16 from shutil import move
18 conffile = sys.argv[1:2]
20 config = ConfigParser()
21 config.add_section('sms')
22 # set defaults for anonymous auth
23 config.set('sms', 'tmpfile', '/tmp/sms.db')
26 sms_db = config.get('sms','tmpfile')
29 conn = sqlite3.connect(sms_db)
32 cur.execute("select ref from sms_parts group by ref having max(datetime) is null or (julianday('now')-julianday(max(datetime)))>0.005;")
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")
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)
44 move(path,'/var/spool/asterisk/outgoing')
45 cur.execute("delete from sms_parts where ref=%s" % (ref))