Skip to content

Instantly share code, notes, and snippets.

@angelopoole
Created January 9, 2017 23:00
Show Gist options
  • Save angelopoole/3f3661feb6157ffac96712f6ddf558e1 to your computer and use it in GitHub Desktop.
Save angelopoole/3f3661feb6157ffac96712f6ddf558e1 to your computer and use it in GitHub Desktop.
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