-
-
Save veirus/2db7f5126cf7241eafa4 to your computer and use it in GitHub Desktop.
Script to organize pictures uploaded from Mobile Devices to Dropbox's Camera Upload folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python34 | |
# dror4 - datetime format edition | 2016.02.27 | |
# Based on https://gist.github.com/dansku/9040240#file-dropboxorganize-py | |
import os.path | |
import glob | |
from datetime import date | |
def move(files, newname): | |
# Move files | |
try: | |
os.rename(files, newname) | |
except FileExistsError: | |
print('[!] File %s already exists, removing duplicate.' % newname) | |
os.remove(files) | |
else: | |
print('Movendo: {0} --> {1}'.format(files, newname).encode('utf-8')) | |
def main(): | |
folder = os.getcwd() | |
print(folder) | |
fileFormats = ('ai', 'bmp', 'cdr', 'jpg', 'jpg-large', 'jpg-orig', 'jpeg', 'mov', 'png', | |
'png-large', 'png-orig', 'pdf', 'psd', 'mp4', 'gif', 'webm', 'webp', | |
'svg', 'flv') | |
twi = ('jpg-large', 'jpg-orig', 'png-large', 'png-orig') | |
months_ru = ('Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', | |
'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь') | |
# Generate list of files | |
pp = (os.path.realpath(i) for f in fileFormats for i in glob.iglob("*.%s" % f)) | |
for files in pp: | |
fixed = '' | |
# Retrieving creation date (getctime() is Windows only): | |
newsub = os.path.join(folder, '{:%Y-%m-%d}'.format(date.fromtimestamp(os.path.getctime(files)))) | |
if files.endswith(twi): | |
fixed = os.path.splitext(files)[0] + os.path.splitext(files)[1][:4] | |
newname = os.path.join(newsub, os.path.basename(fixed or files)) | |
# folder exists? if not, create them! | |
if not os.path.exists(newsub): | |
print('Making dir:', newsub) | |
os.makedirs(newsub) | |
move(files, newname) | |
print("Done :)") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment