def printer1(question): print question # TODO: make this do a google image search and do something intereting with the results options = images.ImageOptions() options.image_type = images.ImageType.CLIPART options.larger_than = images.LargerThan.MP_4 options.color = "green" image_results = google.search_images("banana", options) images.download(image_results, path=TEMP_PATH) print question
def test_get_images_req_url(self): query = "banana" options = images.ImageOptions() options.image_type = images.ImageType.CLIPART options.larger_than = images.LargerThan.MP_4 options.color = "green" req_url = images._get_images_req_url(query, options) exp_req_url = 'https://www.google.com.ar/search?q=banana&es_sm=122&source=lnms&tbm=isch&sa=X&ei=DDdUVL-fE4SpNq-ngPgK&ved=0CAgQ_AUoAQ&biw=1024&bih=719&dpr=1.25&tbs=itp:clipart,isz:lt,islt:4mp,ic:specific,isc:green' self.assertEqual(req_url, exp_req_url)
def webimagesearch(): if not current_user.is_authenticated: return redirect("/index") form = WebImageSearchPostForm() if form.validate_on_submit(): lastQuery.clear() lastQuery.append(form.query.data) options = images.ImageOptions() options.image_type = form.imageType.data options.size_category = form.sizeCategory.data options.larger_than = form.largerThan.data options.exact_width = form.exactWidth.data options.exact_height = form.exactHeight.data options.color_type = form.colorType.data options.color = form.color.data search_results = google.search_images(form.query.data, options) userImageSearch.clear() print(search_results) for result in search_results: somePosts = [{ 'domain': result.domain, 'filesize': result.filesize, 'format': result.format, 'height': result.height, 'index': result.index, 'link': result.link, 'name': result.name, 'page': result.page, 'site': result.site, 'thumb': result.thumb, 'thumb_height': result.thumb_height, 'thumb_width': result.thumb_width, 'width': result.width }] userImageSearch.extend(somePosts) return redirect("/webimagesearch") return render_template('webimagesearch.html', title='Websearch', form=form, userImageSearch=userImageSearch, current_user=current_user, lastQuery=lastQuery)
def findTheColor(strToFind, precision = 10): print "\nLooking for %s" % (strToFind) options = images.ImageOptions() results = google.search_images(strToFind + " logo", options, precision) colorHexa = [] colorLabel = [] for i in range(0, precision): colors = getColorsFromURL(results[i].link) if colors: for z in range(0, len(colors['tags'])): if (colors['tags'][z]['label'] not in ['Beige', 'White', 'Black']): colorHexa.append(colors['tags'][z]['color']) colorLabel.append(colors['tags'][z]['label']) break obj = Counter(colorLabel) c = Color(getRelevant(obj)) colorsToSave.append(c.hex) print "Color is: %s - %s" % (c, c.hex)
def getColor(stringToSearch, precision = 20, keyWords = 'Logo', secondaryColor = False): print "\n\n==========================================================\n\n" print "Looking images for: "+stringToSearch directory = "download/"+stringToSearch # options = images.ImageOptions() options = images.ImageOptions() options.image_type = images.ImageType.CLIPART options.larger_than = images.LargerThan.MP_4 options.color = "green" results = google.search_images("banana", options) print results # results = google.search_images(stringToSearch + " " + keyWords, options, precision) if not os.path.exists(directory): print "\nDownloading images to "+directory os.makedirs(directory) images.fast_download(results, path=directory, threads=precision) listColorHex = [] listColorName = [] print "\nChecking URL and getting colors from:" for i in range(0, precision): print "\n%s (%s/%s) %s" % (stringToSearch, i+1, precision, results[i].link) colors = getColorsFromURL(results[i].link) if colors: for z in range(0, len(colors['tags'])): if colorIsAllowed(colors['tags'][z]['label'].lower()): print ("-> " + colors['tags'][z]['color'] + " - " + colors['tags'][z]['label']) # colorCheck = showColorInfo(colors['tags'][z]['color']) # listColorHex.append(colorCheck['name']['closest_named_hex']) listColorName.append(colors['tags'][z]['label']) listColorHex.append(colors['tags'][z]['color']) if z == 0: listColorName.append(colors['tags'][z]['label']) listColorHex.append(colors['tags'][z]['color']) listColorName.append(colors['tags'][z]['label']) listColorHex.append(colors['tags'][z]['color']) elif z == 1: listColorName.append(colors['tags'][z]['label']) listColorHex.append(colors['tags'][z]['color']) else: print "-> Bad Request (400)" print "" if (listColorName and listColorHex): colorName = Counter(listColorName) colorName = Color(getRelevant(colorName)) colorHex = Counter(listColorHex) colorHex = getRelevant(colorHex) if secondaryColor: sColorHex = getRelevant(Counter(listColorHex), colorHex) print "Color could be: \n-> %s and %s" % (colorHex, sColorHex) return [colorHex, sColorHex] else: print "Color could be: \n-> %s" % (colorHex) return colorHex else: print "Sorry, couldn't find the colors for you. Try to increase the precision. %d it's a little number" % precision return ''
def reset_options(): options = images.ImageOptions() options.color_type = 'color' options.license = 'f' options.larger_than = images.LargerThan.MP_12 return options
break obj = Counter(colorLabel) c = Color(getRelevant(obj)) colorsToSave.append(c.hex) print "Color is: %s - %s" % (c, c.hex) # with open('bancos.csv', 'rb') as f: # reader = csv.reader(f) # for row in reader: # findTheColor(row[2], 20) # sleep(30) precision = 15 options = images.ImageOptions() results = google.search_images("Woori Bank Logo", options, precision) colorHexa = [] colorLabel = [] for i in range(0, precision): print "(%s/%s) %s" % (i+1, precision, results[i].link) colors = getColorsFromURL(results[i].link) if colors: for z in range(0, len(colors['tags'])): if (colors['tags'][z]['label'] not in ['Beige', 'White', 'Black', 'WhiteSmoke', 'gainsboro']): print "-> " + colors['tags'][z]['label'] + " - " + colors['tags'][z]['color'] colorHexa.append(colors['tags'][z]['color']) colorLabel.append(colors['tags'][z]['label']) break
def setup_options(): options = images.ImageOptions() options.size_category = "large" return options