Пример #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
Пример #2
0
setup_environ( settings )

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 )