Last active
February 6, 2017 16:41
-
-
Save DanielRamosAcosta/c0b0dd87abebaffb1d2dab9002d7a9f7 to your computer and use it in GitHub Desktop.
Vacía peliculas para que no ocupen especio pero se quedan como placeholder
This file contains hidden or 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 python | |
| # -*- coding: utf-8 -*- | |
| import argparse, os, re, sys | |
| MIN_MOVIE_SIZE = 5 | |
| pattern = re.compile('.*\.(mkv|avi|mp4)$') | |
| parser = argparse.ArgumentParser(description='Vacía peliculas para que no ocupen especio pero se quedan como placeholder.') | |
| parser.add_argument('directory', metavar='D', type=str, help='nombre del directorio a vaciar') | |
| args = parser.parse_args() | |
| def get_movies_in_dir (root, something): | |
| current = os.path.join(root, something) | |
| if os.path.isfile(current): | |
| return [current] | |
| movies = map(lambda x: get_movies_in_dir(current, x), os.listdir(current)) | |
| return [item for sublist in movies for item in sublist] | |
| def query_yes_no(question, default = 'no', prompt = ' [y/N] '): | |
| valid = {'y': True, 'ye': True, 'yes': True, 'n': False, 'no': False} | |
| while True: | |
| sys.stdout.write(question + prompt) | |
| choice = raw_input().lower() | |
| if choice == '': return valid[default] | |
| elif choice in valid: return valid[choice] | |
| else: sys.stdout.write("Please respond with 'yes' or 'no'.\n") | |
| movies = get_movies_in_dir('.', args.directory) | |
| movies = filter(lambda x: pattern.match(x), movies) | |
| movies = filter(lambda x: os.path.getsize(x) > MIN_MOVIE_SIZE, movies) | |
| for movie in movies: | |
| if query_yes_no('Borrar %s?' % movie): | |
| os.remove(movie) | |
| open(movie, 'a').close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment