Created
March 10, 2015 14:46
-
-
Save Hultner/f7f0080e3bb46623de9d to your computer and use it in GitHub Desktop.
This file contains 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
CREATE OR REPLACE FUNCTION public.sms(f_to text, f_from text, f_message text, f_route text) | |
RETURNS text | |
AS | |
$BODY$ | |
import urllib | |
import urllib2 | |
import ctypes | |
url = "http://server2.msgtoolbox.com/api/current/send/message.php" | |
v_username = 'api_account' | |
v_password = 'api_pass' | |
v_to = f_to | |
v_from = f_from | |
v_message = f_message | |
v_route = f_route | |
v_from = urllib.quote(v_from) | |
v_message = urllib.quote(v_message) | |
url = url + '?username=' + v_username + '&password=' + v_password + '&to=' + v_to + '&from=' + v_from + '&message=' + v_message + '&route=' + v_route | |
user_agent = "Mozilla/4.0 (compatible; MSIE 5.5; WINDOWS NT)" | |
headers = { 'User-Agent' : user_agent } | |
ctypes.cdll.LoadLibrary('libc.so.6').__res_init() | |
req = urllib2.Request(url,'',headers) | |
response = urllib2.urlopen(req) | |
v_response = response.read() | |
return v_response | |
$BODY$ | |
LANGUAGE plpythonu VOLATILE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment