Created
January 19, 2015 21:35
-
-
Save anonymous/e7007163bccb68871d89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import psycopg2 | |
import urllib2 | |
import base64 | |
def GetListWEB(): | |
key = "OmMaNiPadMeHumPokemonchick"; | |
response = urllib2.urlopen("http://sip.svalka.me/call.php?action=read&key="+key).read(); | |
ra = response.split('\r\n'); | |
ClearListWEB(); | |
num=0; | |
date=0; | |
print "list count is ",len(ra) | |
for i in range(len(ra)): | |
if len(ra[i])>0: | |
num=ra[i].split(';')[0]; date=ra[i].split(';')[1]; CheckNumberInListSQL(num,date); | |
return; | |
def ClearListWEB(): | |
key = "OmMaNiPadMeHumPokemonchick"; | |
response = urllib2.urlopen("http://sip.svalka.me/call.php?action=earse&key="+key).read(); | |
print "list is empty"; | |
return; | |
def MakeCall(id,num): | |
request = urllib2.Request("http://10.0.30.10:8080/txtapi/originate?{ignore_early_media=true}sofia/gateway/mango/"+num+"%20"+num+"%20XML%20public") | |
base64string = base64.encodestring('%s:%s' % ('root', 'liluARKn14')).replace('\n', '') | |
request.add_header("Authorization", "Basic %s" % base64string) | |
result = urllib2.urlopen(request).read(); | |
print result; | |
if (result[:1] == "+"): | |
print "ok"; | |
UpdateNumberState(str(id),str(result[5:]),"1"); | |
else: | |
print "no"; | |
UpdateNumberState(str(id),"","2"); | |
return; | |
def InsertNumberInList(num,dstart): | |
try: | |
conn = psycopg2.connect(database="postgres", user="postgres", password="liluARKn14", host="10.0.30.20", port="5432") | |
print "Open connection" | |
except: | |
print "WARNING! I can't open connection" | |
cur = conn.cursor() | |
cur.execute("INSERT INTO webcall (number,date,id_status) VALUES ('"+num+"','"+dstart+"','0')"); | |
conn.commit(); | |
conn.close(); | |
return; | |
def UpdateNumberState(id,uuid,state): | |
try: | |
conn = psycopg2.connect(database="postgres", user="postgres", password="liluARKn14", host="10.0.30.20", port="5432") | |
print "Open connection" | |
except: | |
print "WARNING! I can't open connection" | |
cur = conn.cursor() | |
cur.execute("UPDATE webcall SET id_status='"+state+"',uuid='"+uuid+"' where id='"+id+"' "); | |
conn.commit(); | |
conn.close(); | |
return; | |
def CheckNumberInListSQL(num,dstart): | |
try: | |
conn = psycopg2.connect(database="postgres", user="postgres", password="liluARKn14", host="10.0.30.20", port="5432") | |
print "Open connection" | |
except: | |
print "WARNING! I can't open connection" | |
cur = conn.cursor() | |
idn = 0; | |
cur.execute("SELECT id, number, date, id_status, id_user from webcall where number='" + str(num) + "' and date='"+ str(dstart) + "'") | |
rows = cur.fetchall() | |
if len(rows)<1: | |
print "insert",num,dstart; InsertNumberInList(num,dstart); | |
if len(rows)<1: | |
for row in rows: | |
print "id = ", row[0] | |
print "number = ", row[1] | |
print "date = ", row[2] | |
print "id_status = ", row[3] | |
print "id_user = ", row[4], "\n" | |
conn.close() | |
print "Close connection" | |
return; | |
def GetListInSQL(): | |
try: | |
conn = psycopg2.connect(database="postgres", user="postgres", password="liluARKn14", host="10.0.30.20", port="5432") | |
print "Open connection" | |
except: | |
print "WARNING! I can't open connection" | |
cur = conn.cursor() | |
idn = 0; | |
cur.execute("SELECT id, number, date, id_status, id_user from webcall where id_status=0") | |
rows = cur.fetchall() | |
if len(rows)<1: | |
print "no calls"; | |
if len(rows)>0: | |
for row in rows: | |
print "id = ", row[0] | |
print "number = ", row[1] | |
print "date = ", row[2] | |
print "id_status = ", row[3] | |
print "id_user = ", row[4], "\n" | |
MakeCall(row[0],row[1]); | |
conn.close() | |
print "Close connection" | |
return; | |
GetListWEB(); | |
GetListInSQL(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment