From 4f08494370d226b168f485253db2d87ef2da4222 Mon Sep 17 00:00:00 2001 From: pepperpepperpepper Date: Sun, 4 Oct 2015 16:16:35 -0700 Subject: cleanup --- ricky/im.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ricky/im.py (limited to 'ricky/im.py') diff --git a/ricky/im.py b/ricky/im.py new file mode 100644 index 0000000..91bf2c1 --- /dev/null +++ b/ricky/im.py @@ -0,0 +1,29 @@ +import urllib +import urllib2 +import sys +import random +import simplejson as json +import urllib2 + +class Im: + def __init__(self): + self._required_keys = [] + self.url = "" + def post_request(self, url, params): + params = urllib.urlencode(params) + headers = { + "Content-type": "application/x-www-form-urlencoded", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36", + "Accept": "text/plain" + } + try: + req = urllib2.Request(url, params, headers) + response = urllib2.urlopen(req) + return response.read() + except Exception as e: + sys.stderr.write(str(e)) + raise + def call(self, params): + if not(params.is_ready()): + raise Exception("Im Params Not Ready") + return json.loads(self.post_request(self.url, params.as_hash())) -- cgit v1.2.3-70-g09d2