jci's blog

Earthquakes can't stop the rock

« You know? Just enjoy the big show. We'll talk later. :: Pretty much like Nutella and Chocolate, but with less fat »

Escrito el 05/23/11 02:40:36 pm por jci

After all this bullshit, something must come to a good end

Categories: Web Link Blog, GNOME, GNU/Linux, Programacion, Hacks

Hace 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)
2882 views » Send feedback »

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)

Acerca de este glob

On the Sixth Day, there was a Running Man looking for a Predator to stop a Raw Deal with a Commando. Only True Lies were said. But nao, Junior is about to get Twins, with the help of a Kindergarden Cop. That will be the Terminator of all struggles.

Archives