-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbconnect.py
64 lines (55 loc) · 1.48 KB
/
dbconnect.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
import MySQLdb
import sys
import os
import subprocess
import time
while ('true'):
# Open database connection
db = MySQLdb.connect("localhost","smpp","passwordhere","tsmsd" )
dbupdate = MySQLdb.connect("localhost","smpp","passwordhere","tsmsd")
# prepare a cursor object using cursor() method
cursor = db.cursor()
cursorupdate = dbupdate.cursor()
# Prepare SQL query to INSERT a record into the database.
sql = "SELECT text,number,processed,id FROM outbox \
WHERE processed <= '%d'" % (0)
print(sql)
try:
cursor.execute(sql)
# Fetch all the rows in a list of lists.
results = cursor.fetchall()
print results
for row in results:
text = row[0]
phone = row[1]
processed = row[2]
id = row[3]
# Now print fetched result
print "text=%s,phone=%s,processed=%d" % \
(text, phone, processed )
if (phone == 'None'):
print('phone=None')
sys.exit()
else:
try:
print('Body SQL Here')
try:
subprocess.call(["/opt/python-smpplib-master/sendsms.py","-t",text,"-d",phone])
except:
print('Check IPSec Connection JOPA')
sqlupdate = "UPDATE outbox SET processed=1 where id='%d'" % (id)
print(sqlupdate)
#cursorupdate = dbupdate.cursor()
cursorupdate.execute(sqlupdate)
#dbupdate.commit()
except:
print('Ls')
#dbupdate.rollback()
except:
print "Error: unable to fecth data"
dbupdate.commit()
dbupdate.close()
# disconnect from server
db.close()
time.sleep(5)
pass