diff options
Diffstat (limited to 'ricky/pb.py')
| -rw-r--r-- | ricky/pb.py | 38 |
1 files changed, 3 insertions, 35 deletions
diff --git a/ricky/pb.py b/ricky/pb.py index 4a94a46..456ff85 100644 --- a/ricky/pb.py +++ b/ricky/pb.py @@ -1,47 +1,15 @@ import os -import urllib -import urllib2 import sys import simplejson as json from ricky.config import OFFLINE, PB_DATA_URL +import ricky.utils as utils class Pb(object): def __init__(self): - self._required_keys = [] self.url = "" self._offline = OFFLINE - def http_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: - 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) - ) - def call(self, params): if self._offline: sys.path.append("./photoblaster") @@ -56,7 +24,7 @@ class Pb(object): instance.file_s3move() return instance.file_dict() return json.loads( - self.http_request(self.url, params=params.as_dict()) + utils.http_request(self.url, params=params.as_dict()) ) def data_from_url(self, url): @@ -77,5 +45,5 @@ class Pb(object): sys.stderr.write("No usable data found in db\n") return None else: - print self.http_request("%s?newfile=%s" % (PB_DATA_URL, newfile)) + print utils.http_request("%s?newfile=%s" % (PB_DATA_URL, newfile)) raise NotImplementedError("Not yet implemented\n") |
