def fetchShots(): count = 0 page = 0 outfile = io.open(FILENAME, 'w', encoding='utf-8') palettes = [] # Array of each image data to be pickled training_data = [] outfile.write(u"@relation colours\n") colorclassifier = Classifier() colours = dict.fromkeys(colorclassifier.getColours().keys(), 0) for colour in colours: colour = colour.replace(' ','') colour = colour.replace("'",'') outfile.write(u"@attribute " + colour + " {yes, no}\n") outfile.write(u"@data\n") for i in range(0, DRIBBBLE_NUMBER_IMAGES): # 50 is the maximum per page resp = drib.shots('popular', per_page=10, page=page) for shot in resp["shots"]: # Get the image and open it response = requests.get(shot["image_teaser_url"], stream=True) #response = requests.get(shot["image_teaser_url"]) raw_image = cStringIO.StringIO(response.content) img = Image.open(raw_image).convert('RGB') palette = getPalette(img) print palette user_id = shot["id"] # Reset the colours for colour in colours: colours[colour] = 0 if palette is not None: drawPalette(palette, img) palettes.append(palette) j = 0 for colour in palette: classifiedColour = colorclassifier.getColourName(colour) print("colour " + str(j) + ": " + classifiedColour + " ") colours[classifiedColour] += 1 j += 1 # print(colours) training_data.append(copy.copy(colours)) outfile.write(u','.join("yes" if colours[colour] > 0 else "no" for colour in colours)) outfile.write(u"\n") raw_input("Press Enter to continue...") count += 50 if count >= DRIBBBLE_NUMBER_IMAGES: break page += 1 td_file = io.open("training_data.pkl", 'wb') pickle.dump(training_data, td_file) td_file.close()
def test_shots_for_an_individual(self): d.shots('simplebits') expected = "http://api.dribbble.com/players/simplebits" self.get.assert_called_with(expected, params={})
def test_shots_for_popular(self): d.shots('popular') expected = "http://api.dribbble.com/shots/popular" self.get.assert_called_with(expected, params={})
def get_popular_shots(): resp = dribbble.shots('popular')() if 'shots' in resp: return resp['shots']