def get_marvel_characters(number_of_characters, marvel_public_key, marvel_private_key):
 timestamp = str(int(time.time()))
 hash_value = hashlib.md5(((timestamp + marvel_private_key) + marvel_public_key)).hexdigest()
 characters = []
 for _num in xrange(number_of_characters):
  offset = random.randrange(1, 1478)
  limit = '1'
  url = ((((((((('http://gateway.marvel.com:80/v1/public/characters?limit=' + limit) + '&offset=') + str(offset)) + '&apikey=') + marvel_public_key) + '&ts=') + timestamp) + '&hash=') + hash_value)
  headers = {'content-type': 'application/json'}
  request = requests.get(url, headers=headers)
  data = json.loads(request.content)
  if (data.get('code') == 'InvalidCredentials'):
   raise RuntimeError('Your Marvel API keys do not work!')
  character = data['data']['results'][0]['name'].strip().replace(' ', '_')
  characters.append(character)
 return characters

def get_marvel_characters ( number_of_characters , marvel_public_key , marvel_private_key ) : timestamp = str ( int ( time . time ( ) ) ) hash_value = hashlib . md5 ( ( ( timestamp + marvel_private_key ) + marvel_public_key ) ) . hexdigest ( ) characters = [ ] for _num in xrange ( number_of_characters ) : offset = random . randrange ( 1 , 1478 ) limit = '1' url = ( ( ( ( ( ( ( ( ( 'http://gateway.marvel.com:80/v1/public/characters?limit=' + limit ) + '&offset=' ) + str ( offset ) ) + '&apikey=' ) + marvel_public_key ) + '&ts=' ) + timestamp ) + '&hash=' ) + hash_value ) headers = { 'content-type' : 'application/json' } request = requests . get ( url , headers = headers ) data = json . loads ( request . content ) if ( data . get ( 'code' ) == 'InvalidCredentials' ) : raise RuntimeError ( 'Your Marvel API keys do not work!' ) character = data [ 'data' ] [ 'results' ] [ 0 ] [ 'name' ] . strip ( ) . replace ( ' ' , '_' ) characters . append ( character ) return characters
makes an api call to the marvel comics developer api to get a list of character names .