Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import http.client
- import json
- import time
- import timeit
- import pickle
- def get_colors(quantity=5, api_key=None):
- conn = http.client.HTTPSConnection("rebrickable.com")
- key = api_key
- auth_token = {'Authorization': 'key '+key}
- payload = "{}"
- headers = auth_token
- params = '/api/v3/lego/colors/?page=1&page_size='+str(quantity) # modify this so that results are limited by the `quantity` argument.
- conn.request("GET", params, payload, headers=headers)
- response = json.loads(conn.getresponse().read().decode('UTF-8'))["results"]
- colors = []
- for c in response:
- colors.append(c['name'])
- ################################################################
- # insert code to handle data returned in the response #
- # return a list of strings, one string for each color returned #
- ################################################################
- return colors
- # uncomment these next 2 lines to test your implementation
- colors = get_colors(quantity=5, api_key='83ce576bdf6440495ba3f11f351a3be7')
- print(colors)
- # The following is sample output of the get_colors() function and is used only to exmplify
- # the format of the results for this cell.
- # you may comment out or delete the below line.
- # print("\n-------------sample-output-------------")
- # print(['Fuschia', 'Magenta', 'Violet', 'Pink', 'White'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement