Last active
August 29, 2015 14:11
-
-
Save EnriqueSoria/ff21736a6b3241813449 to your computer and use it in GitHub Desktop.
Mueve ficheros .torrent a subcarpetas según ciertas palabras claves.
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
# -*- coding: utf-8 -*- | |
''' Clasifica torrents según ciertas palabras clave ''' | |
kwords = { | |
'windows': ['win', 'exe', 'msi', 'pc'], | |
'mac': ['mac', 'osx', 'dmg'], | |
'linux': ['rpm', 'deb', 'tar', 'linux', 'ubuntu', 'sh'], | |
'ost': ['flac', 'ost', 'flac', 'mp3', 'soundtrack'], | |
'android': ['apk', 'android'] | |
} | |
files = { | |
'windows': [], | |
'mac': [], | |
'linux': [], | |
'ost': [], | |
'android': [] | |
} | |
from os import listdir as ls | |
for fileName in ls('.'): | |
# Per a cada fitxer, si es un torrent | |
if not fileName.endswith('.torrent'): | |
continue | |
for key, values in kwords.iteritems(): | |
# Per a cada posible clasificació | |
for kword in values: | |
# Mirem si coincideix en algunes de les kwords | |
if kword.lower() in fileName.lower(): | |
files[key].append(fileName) | |
break | |
from os import rename as mv | |
from os import mkdir | |
from os import path | |
''' movemos todos los ficheros a su correspondiente carpeta ''' | |
errores = 0 | |
for dst, files_arr in files.iteritems(): | |
try: | |
mkdir(dst) | |
except: pass | |
fPath = path.abspath('.\\%s'%dst) | |
print fPath | |
for fName in files_arr: | |
try: | |
mv(fName, '%s\\%s' % (fPath, fName)) | |
except: errores+=1; continue | |
print 'Han habido %s errores' % errores |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment