예제 #1
0
def _save_json(filename):
    if filename and config.get('images'):
        data = {}
        for img in config['images']:
            img_data = requests.get(img['url']).content
            b64_img_data = base64.b64b64encode(img_data)
            str_img_data = b64_img_data.decode('utf-8')
            data[img['name']] = str_img_data

        with open(filename, 'w') as ijson:
            ijson.write(json.dumps(data))
        _alert('Done')
예제 #2
0
def encode(message, encoding="base64"):
    """
    Arguments:
        message - A bytes string representing the object to be encoded
        encoding - the type of encoding that should be used

    return:
        a message encoded with the spceified encoding type

    """

    if encoding in supported_encodings:
        if encoding == "base58":
            return base58.b58encode(message)
        elif encoding == "base64":
            return base64.b64b64encode(message)
    else:
        raise UnsupportedEncoding
예제 #3
0
 def get_oauth_token():
     http_obj = Http()
     url = "https://api.idealista.com/oauth/token"
     key = API_PUBLIC + ":" + API_SECRET
     # Encode key to base64
     key_bytes = key.encode('ascii')
     key_base64 = base64.b64b64encode(key_bytes)
     auth = key_base64.decode('ascii')
     body = {'grant_type': 'client_credentials', 'scope': 'read'}
     headers = {
         'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
         'Authorization': auth
     }
     resp, content = http_obj.request(url,
                                      method='POST',
                                      headers=headers,
                                      body=urllib.parse.urlencode(body))
     content = json.loads(content)
     return content["access_token"]
예제 #4
0
 def read_files(self, path):
     with open(path, "rb") as file:
         return base64.b64b64encode(file.read())