diff options
| author | pepperpepperpepper <pepper@scannerjammer.com> | 2015-12-08 12:46:23 -0800 |
|---|---|---|
| committer | pepperpepperpepper <pepper@scannerjammer.com> | 2015-12-08 12:46:23 -0800 |
| commit | 0b994e3b71c2c0b463d100edd07745af565c7a59 (patch) | |
| tree | 2a7c7b5834859684400e770a22eecb62fc41592b /ricky/utils.py | |
| parent | 17fff32864cf33bbec2b531a6123618acf74f3f7 (diff) | |
changed structure, added utils
Diffstat (limited to 'ricky/utils.py')
| -rw-r--r-- | ricky/utils.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/ricky/utils.py b/ricky/utils.py new file mode 100644 index 0000000..e887fa0 --- /dev/null +++ b/ricky/utils.py @@ -0,0 +1,34 @@ +import sys +import urllib +import urllib2 + + +def http_request(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: + if params: + req = urllib2.Request(url, params, headers) + else: + req = urllib2.Request(url, params, headers) + response = urllib2.urlopen(req) + return response.read() + except ValueError: + sys.stderr.write( + "Bad Post params or Url sent to photoblaster" + "api.\n" + ) + except urllib2.URLError: + sys.stderr.write( + "Could not complete post request to the given url:\n" + + ("URL: %s\n" % url) + + ("PARAMS: %s\n" % params) + ) |
