Last active
August 29, 2015 13:57
-
-
Save sigsergv/9351755 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# This code is in public domain | |
import httplib2 | |
import urllib | |
import random | |
from xml.etree.ElementTree import Element, SubElement, Comment, tostring | |
from xml.dom import minidom | |
from optparse import OptionParser | |
from sys import exit | |
parser = OptionParser() | |
parser.add_option("", "--user", dest="user", help="Username", metavar="USER", default=False) | |
parser.add_option("", "--password", dest="password", help="Password", metavar="PASSWORD", default=False) | |
parser.add_option("", "--phone", dest="phone", help="Phone number", metavar="PHONE", default=False) | |
(options, args) = parser.parse_args() | |
if not options.user or not options.password or not options.phone: | |
print "All args are required" | |
parser.print_help() | |
exit(1) | |
httplib2.debuglevel = 9 | |
USER = options.user | |
PASSWORD = options.password | |
PHONE_NUMBER = options.phone | |
GATEWAY_URL = 'https://atompark.com/members/sms/xml.php' | |
sms = Element('SMS') | |
operations = Element('operations') | |
operation = Element('operation') | |
operation.text = 'BALANCE' | |
operations.append(operation) | |
sms.append(operations) | |
authentification = Element('authentification') | |
username = Element('username') | |
password = Element('password') | |
username.text = USER | |
password.text = PASSWORD | |
authentification.append(username) | |
authentification.append(password) | |
sms.append(authentification) | |
message = Element('message') | |
sender = Element('sender') | |
sender.text='sms-info' | |
text = Element('text') | |
text.text = u'Example Text Message' | |
message.append(sender) | |
message.append(text) | |
sms.append(message) | |
numbers = Element('numbers') | |
number = Element('number') | |
number.text = PHONE_NUMBER | |
numbers.append(number) | |
sms.append(numbers) | |
xml = tostring(sms, encoding='UTF-8') | |
xml = minidom.parseString(xml).toprettyxml(indent=" ") | |
xml = xml.encode('utf-8') | |
boundary = '-' * 21 + str(int(random.random() * 1000)) | |
headers = {'Content-Type': 'multipart/form-data; boundary=%s' % boundary,} | |
body = '--' + boundary + '\r\n' + \ | |
'Content-Disposition: form-data; name="XML"\r\n\r\n' + \ | |
xml + '\r\n--' + boundary + '--\r\n' | |
client = httplib2.Http() | |
resp, content = client.request(GATEWAY_URL, | |
method='POST', | |
headers=headers, | |
body=body) | |
print "Resp: %s" % (resp, ) | |
print "Content: %s" % (content, ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment