After all this bullshit, something must come to a good end
Categories: Web Link Blog, GNOME, GNU/Linux, Programacion, HacksHace un tiempo atras, Claudio subio un script en Python que permite esto:
jci@rock:~/Photos/l$ ls
IMG_1190.JPG IMG_1191.JPG IMG_1192.JPG IMG_1193.JPG
jci@rock:~/Photos/l$ ~/scripts/picsdir.py .
IMG_1191.JPG
creating dir ./2011-05-23
./2011-05-23
IMG_1192.JPG
./2011-05-23
IMG_1193.JPG
./2011-05-23
IMG_1190.JPG
./2011-05-23
Traceback (most recent call last):
File "/home/jci/scripts/picsdir.py", line 66, in <module>
print sum(getsize(join(root, name)) for name in files)
NameError: name 'files' is not defined
jci@rock:~/Photos/l$ ls
2011-05-23
Pero desde que me dio por actualizar a Natty...
jci@socrates:~/Photos/untitled folder 2$ ~/scripts/picsdir.py .
IMG_1101.JPG
Traceback (most recent call last):
File "/home/jci/scripts/picsdir.py", line 64, in <module>
start=Main(sys.argv)
File "/home/jci/scripts/picsdir.py", line 62, in Main
move_smartly (filename, dir_in, dir_out)
File "/home/jci/scripts/picsdir.py", line 29, in move_smartly
image = pyexiv2.Image(image_file)
AttributeError: 'module' object has no attribute 'Image'
Nada que un hack no pueda hacer :-)
#!/usr/bin/env python # Copyright (C) 2008 Claudio Saavedra# modified by jci :-) # You should have received a copy of the GNU General Public License # along with this program. If not, see . import sys import pyexiv2 import os import os.path import shutil import mimetypes def move_smartly(file, dir_in, dir_out): image_file = os.path.join (dir_in, file) image = pyexiv2.ImageMetadata(image_file) image.read() try: date_creation = image['Exif.Image.DateTime'] except: print "i'm ignoring this" return print date_creation str_date = date_creation.value.strftime('%Y-%m-%d') target_dir = os.path.join (dir_out, str_date) if (not os.path.exists(target_dir)): print "creating dir " + target_dir os.mkdir(target_dir) print target_dir shutil.move (image_file, target_dir) def Main(args): if (len (args) < 1): sys.exit("not enough parameters") dir_in = args[1] if (len (args) < 3): dir_out = dir_in else: dir_out = args[2] for root, dirs, files in os.walk (dir_in): for f in files: print f filename = os.path.join (root, f) if mimetypes.guess_type(filename)[0] == 'image/jpeg': move_smartly (filename, dir_in, dir_out) start=Main(sys.argv) print sum(getsize(join(root, name)) for name in files)




