def update_all(): all = Photo.objects.all() # c = len(allobj) # span = 50 # step = c/50 # for j in range(0,step): # all = allobj[j*span:(j+1)*span] if True: for i in all: if i.image: orientation = 1 print i if i.orientation > 0: print "skip" continue image_url = i.image.path scan = Scanner(image_url) exif = scan.scanExif() try: if exif.has_key(274): orientation = int(exif[274]) except: pass print "orientation: ", orientation try: i.orientation = orientation i.save() except: print "error"
def update_image(authors, image_url, j): """ Arguments: - `authors`: - `path`: - `name`: """ orientation = None if True: print "full path: ",image_url if True: scan = Scanner(image_url) exif = scan.scanExif() try: if exif: if exif.has_key(36867): # DateTimeOriginal published_at = date_validate(exif[36867], "%Y:%m:%d %H:%M:%S") elif exif.has_key(36868): # DateTimeDigitized published_at = date_validate(exif[36868], "%Y:%m:%d %H:%M:%S") elif exif.has_key(306): # DateTime published_at = date_validate(exif[306], "%Y:%m:%d %H:%M:%S") else: # now published_at = date_validate("%s-04-01" % year) else: published_at = datetime.datetime.now() except: published_at = datetime.datetime.now() try: if exif.has_key(274): orientation = int(exif[274]) except: pass print "published at: ", published_at print "orientation: ", orientation alltag = [] photo = Photo.get_by_pub_and_name(published_at, j) if photo: print "photo is already istalled" return 0 else: photo = Photo() photo.caption = j.split(".")[0] if orientation: photo.orientation = orientation photo.published_at = published_at photo.save(isFirst = True) name = force_unicode(photo.published_at.strftime((smart_str("%Y%m%d%H%M%S_"+str(photo.id).zfill(5)+"."+j.split(".")[-1])))) photo.title = name from django.core.files import File image = File(open(image_url)) print image,image.size,name photo.image = image photo.original_title = j for a in authors: photo.authors.add(a) photo.tag.clear() tags = "" if alltag: for t in alltag: tt = Tag.get_by_id(t) photo.tag.add(tt) tags += "%s," % tt.name photo.save()