Пример #1
0
def search_comics(id):
    timestamp, public_key, hash = generate_keys()
    response = requests.get(
        'http://gateway.marvel.com/v1/public/comics/{}?ts={}&apikey={}&hash={}'
        .format(id, timestamp, public_key, hash))
    if response.status_code == 200:
        comics = response.json()['data']['results'][0]
        return Comics(id=comics['id'],
                      title=comics['title'],
                      description=comics['description'],
                      format=comics['format'],
                      pageCount=comics['pageCount'],
                      urls=comics['urls'])
    else:
        return None
Пример #2
0
def find_serie_comics(id, limit, offset):
    timestamp, public_key, hash = generate_keys()
    if offset != None:
        response = requests.get('http://gateway.marvel.com/v1/public/series/{}/comics?limit={}&offset={}&ts={}&apikey={}&hash={}'.format(id, limit, offset, timestamp, public_key, hash))
    else:
        response = requests.get('http://gateway.marvel.com/v1/public/series/{}/comics?limit={}&ts={}&apikey={}&hash={}'.format(id, limit, timestamp, public_key, hash))
    if response.status_code == 200:
        comics = []
        for data in response.json()['data']['results']:
            comics.append(Comics(
                id=data['id'],
                title=data['title'],
                description=data['description'],
                format=data['format'],
                pageCount=data['pageCount'],
                urls=data['urls']
            ))
        return comics
    else:
        return None