Beispiel #1
0
	def job( self ):
		try:
			products = Product.products_with_default_image.all()[0: CronAddImagesJob.NUM_PRODUCTS]
			for product in products:
				if product.image == ProductsWithDefaultImageManager.DEFAULT_IMAGE:
					image_ripper = ImageRipper( directory = MEDIA_ROOT )
					image = image_ripper.rip_one_image( product.name.encode( 'utf-8' ) )
					if image != None:
						product.image = image
						product.save()
		except:
			pass
Beispiel #2
0
from products.models import Product
from dargent.imageripper import ImageRipper
from dargent.settings import MEDIA_URL, MEDIA_ROOT
from products.models import DefaultImageManager
from dargent.models import ThumbnailModel
import os
import re

products = Product.products_with_default_image.all()
i = 0
for product in products:
	if product.image == DefaultImageManager.DEFAULT_IMAGE:
		dir2 = os.path.join( MEDIA_ROOT, "products/" )
		image_ripper = ImageRipper( directory = dir2 )		
		try:
			image = image_ripper.rip_one_image( product.name.encode( 'utf-8' ) )
		except IOError:
			continue
		except TypeError:
			continue
		if image != None:
			print "image={0}".format( image )
			groups = re.match( r'(.+)\.(.+)', image )
			if groups == None:
				filename = image
				ext = ""
			else:
				filename = groups.group( 1 )
				ext = "." + groups.group( 2 )
			if len( filename ) > 18:
				filename = filename[ 0: 18 ]