Created
April 11, 2012 17:25
-
-
Save Xenefungus/2360706 to your computer and use it in GitHub Desktop.
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 python | |
#uStole calculates the estimated value of media files on your computer based on filetypes. | |
#Features to come: | |
#support to factor in series and tv shows more realistically | |
import sys | |
import os | |
import collections | |
from operator import itemgetter | |
import time | |
#okay, let's be user-friendly! | |
if len(sys.argv) != 2: | |
print "Usage:" | |
print "python uStole.py PATH_TO_YOUR_MEDIA_FILES_DIRECTORY" | |
else: | |
print "Welcome to uStole!", | |
print "Let's see how much your hard drive's content is worth." | |
#Values for different kinds of filetypes | |
#Change to your liking to better represent your location | |
#Defaults should be valid for both European and US regions and represent Euros and Dollars, respectively. | |
typeCosts = { | |
".mp3":1, | |
".ogg":1, | |
".flac":2, | |
".mkv":10, | |
".avi":5, | |
".ogm":5, | |
".pdf":3, | |
".opf":1, | |
".mobi":1, | |
".epub":1, | |
".wma":1, | |
".mp4":5, | |
".wmv":5, | |
".iso":50 | |
} | |
validTypes = typeCosts.keys() | |
print "The following file types are currently factored in: " | |
for filetype in validTypes: | |
print filetype, | |
print "\n" | |
sys.stdout.write("Examining your files now... ") | |
sys.stdout.flush() | |
totalFiles = 0 | |
toCalc = {} | |
path = sys.argv[1] | |
extensions = collections.defaultdict(int) | |
numberOfTypes = len(extensions) | |
for path, dirs, files in os.walk(path): | |
for filename in files: | |
extensions[os.path.splitext(filename)[1].lower()] += 1 | |
for key, value in sorted(extensions.iteritems(), key=itemgetter(1), reverse=True): | |
totalFiles += value | |
if key in validTypes: | |
toCalc[key] = value | |
sys.stdout.write("[Done]") | |
sys.stdout.flush() | |
time.sleep(1) | |
print "\n" | |
print "A total amount of", totalFiles, "files were found in your chosen directory and below." | |
totalSum = 0 | |
print "Type".ljust(7), "Number".rjust(7), "Cost".rjust(7) | |
for k in sorted(toCalc.iteritems(), key=itemgetter(1), reverse=True): | |
fileTypeSum = typeCosts[k[0]]*k[1] | |
totalSum += fileTypeSum | |
print k[0].ljust(7), str(k[1]).rjust(7), str(fileTypeSum).rjust(7) | |
print "\n" | |
print "You stole approximately", totalSum, "units of your currency from the media industry." | |
print "Do you feel bad about it?" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment