def do_service(self, longurl): longurl = self._quote_url(longurl) req = self.base % longurl try: resp = self._get_request(req) return ServiceResponse(resp) except Exception, error: self.log.debug("Error: %s\n%s" % (error, traceback.print_exc())) return ServiceResponse(err=True, err_msg=_('Problem shorting URL'))
def do_service(self, keyurl): longurl = self._quote_url(keyurl) req = self.base % (VERSION, APP, APIKEY, longurl) try: resp = self._json_request(req) return ServiceResponse(resp['results'][keyurl]['shortUrl']) except Exception, error: self.log.debug("Error: %s\n%s" % (error, traceback.print_exc())) return ServiceResponse(err=True, err_msg=_('Problem shorting URL'))
def do_service(self, keyurl): longurl = self._quote_url(keyurl) req = self.base % longurl try: resp = self._json_request(req) #print resp short = "http://smlk.es/%s" % resp['link'] return ServiceResponse(short) except Exception, error: self.log.debug("Error: %s\n%s" % (error, traceback.print_exc())) return ServiceResponse(err=True, err_msg=_('Problem shorting URL'))
def do_service(self, longurl): values = {'submit': 'Make it an ur1!', 'longurl': longurl} try: data = urllib.urlencode(values) resp = self._get_request(self.base, data) short = self.pt.findall(resp) if len(short) > 0: return ServiceResponse(short[0]) else: raise Exception except Exception, error: self.log.debug("Error: %s\n%s" % (error, traceback.print_exc())) return ServiceResponse(err=True, err_msg=_('Problem shorting URL'))
def do_service(self, username, password, filepath): _file = open(filepath, 'r') files = (('media', self._get_pic_name(filepath), _file.read()), ) _file.close() fields = ( ('username', username), ('password', password), ) try: resp = self._upload_pic(self.server, self.base, fields, files) link = self._parse_xml('mediaurl', resp) return ServiceResponse(link) except Exception, error: self.log.debug("Error: %s\n%s" % (error, traceback.print_exc())) return ServiceResponse(err=True, err_msg=_('Problem uploading pic'))