Commit 8205d69a by source_reader

removed keys

parent 92d4bc41
Showing with 60 additions and 0 deletions
import hashlib
import time
import requests
import io
import pygame
class MarvelClient:
def __init__(self, public_key, private_key):
self.public_key = public_key
self.private_key = private_key
self.api_url = "http://gateway.marvel.com:80/v1/public"
def get_characters(self):
params = self.__generate_auth_params()
resp = requests.get(self.api_url + "/characters", params=params)
json = resp.json()
characters = []
for item in json['data']['results']:
# turn thumbnail into image url
thumb = item['thumbnail']
image_url = thumb['path'] + "/portrait_xlarge." + thumb['extension']
characters.append(Character(item['name'],
item['description'],
image_url,
item['comics'],
item['series']))
return characters
def __generate_auth_params(self):
now = str(time.time())
msg = (now + self.private_key + self.public_key).encode('ascii')
hash = hashlib.md5(msg).hexdigest()
return {
"ts": now,
"hash": hash,
"apikey": self.public_key
}
class Character:
def __init__(self, name, description, image_url, comics, series):
self.name = name
self.description = description,
self.image_url = image_url
self.comics = comics,
self.series = series
def get_image(self):
resp = requests.get(self.image_url)
img_bytes = io.BytesIO(resp.content)
img = pygame.image.load(img_bytes)
return img
# test library code
if __name__ == "__main__":
my_client = MarvelClient("7e583905d15a48c849ef155bc9d6af29",
"f8307f988ea51a41040df0c273cd5ab36606d58d")
my_client.get_characters()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment