Ejemplo n.º 1
0
 def handle(self, *args, **options):
     #t0 = datetime.datetime.now()
     
     api = FiveHundredPx(CONSUMER_KEY)
     
     iiter = api.get_photos(feature = args[0])
     
     count = 0
     for p in iiter:
         if count>1000:
             break
         count += 1
         
         url = p['image_url']
         fileIm = urllib.urlopen(url)
     
         im = StringIO(fileIm.read())
         img = Image.open(im)
         
         
         pixel = Pixel()
         
         pixel.url = 'http://500px.com/photo/%d' % p['id']
         
         filename = hashlib.md5(im.getvalue()).hexdigest()+'.jpg'
         pixel.image1.save(name=filename, content=ContentFile(im.getvalue()), save=False)
         
         
         color = (r,g,b) = average_color(img)
         (qr,qg,qb) = quantize_color(color)
         
         pixel.r=r
         pixel.g=g
         pixel.b=b
         
         pixel.qr=qr
         pixel.qg=qg
         pixel.qb=qb
         
         pixel.save()
             
     
     #self.stdout.write("Popular Looks reloaded, in %s" % delta_t)
Ejemplo n.º 2
0
    def handle(self, *args, **options):
        #t0 = datetime.datetime.now()
        
        api = FiveHundredPx(settings.PX_CONSUMER_KEY)
        
        iiter = api.get_photos(feature = args[0], limit=1000)
        
        for p in iiter:
            url = p['image_url']
            fileIm = urllib.urlopen(url)
        
            im = StringIO(fileIm.read())
            try:
                img = Image.open(im)
            except:
			    print 'problem featching image path: %s' % (url)
			    continue
            
            
            pixel = Pixel()
            
            pixel.url = 'http://500px.com/photo/%d' % p['id']
            
            filename = hashlib.md5(im.getvalue()).hexdigest()+'.jpg'
            pixel.image1.save(name=filename, content=ContentFile(im.getvalue()), save=False)
            
            
            color = (r,g,b) = average_color(img)
            (qr,qg,qb) = quantize_color(color)
            
            pixel.r=r
            pixel.g=g
            pixel.b=b
            
            pixel.qr=qr
            pixel.qg=qg
            pixel.qb=qb
            
            pixel.save()