Created
January 9, 2017 23:00
-
-
Save angelopoole/3f3661feb6157ffac96712f6ddf558e1 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
import csv | |
import sys | |
import locale | |
locale.setlocale(locale.LC_ALL, '') | |
csv_filepath = sys.argv[1] | |
winners = [] | |
losers = [] | |
with open(csv_filepath, 'rb') as csvfile: | |
rows = csv.reader(csvfile) | |
is_header = True | |
for row in rows: | |
if is_header: | |
is_header = False | |
continue | |
title = row[2] | |
week = row[7] | |
total_gross = row[5] # '$123,123,123' | |
total_gross = int(total_gross[1:].replace(',','')) | |
budget = row[6] # '$123' | |
if not budget: | |
continue | |
budget = int(budget[1:].replace(',','')) * 1000000 | |
if total_gross > budget: | |
winners.append({ | |
'title': title, | |
'total_gross': total_gross, | |
'budget': budget, | |
'week' : week, | |
}) | |
else: | |
losers.append({ | |
'title': title, | |
'total_gross': total_gross, | |
'budget': budget, | |
'week' : week, | |
}) | |
print title | |
print 'Box Office Winners: ' | |
print '====================' | |
for winner in winners: | |
total_gross = winner['total_gross'] | |
budget = winner['budget'] | |
profit = total_gross - budget | |
print '"{0}" Profit: {1} week:{2}'.format( | |
winner['title'], | |
locale.currency(profit, grouping=True), | |
winner['week']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment