Skip to content

Instantly share code, notes, and snippets.

@jkeesh
Created January 11, 2015 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkeesh/314d8c2b81714d50d405 to your computer and use it in GitHub Desktop.
Save jkeesh/314d8c2b81714d50d405 to your computer and use it in GitHub Desktop.
uber reporting
import csv
import sys
import pprint
FIRST_ROW = 6
DATE_INDEX = 1
EMAIL_INDEX = 7
FARE_INDEX = 14
MONTH_INDEX = 0
YEAR_INDEX = 2
all_time = False
if len(sys.argv) < 2:
print "Improper usage. Expected 2 arguments. Usage: "
print "\n\tpython uber_report.py MONTH YEAR\n\n"
print "Example, for October 2015 "
print "\n\tpytohn uber_report.py 10 15\n\n"
print "To get all time use:\n"
print "\tpython uber_report.py --alltime\n\n"
sys.exit()
if '--alltime' in sys.argv:
all_time = True
if not all_time:
# Get an int version of the 2 digit month
month = int(sys.argv[1])
# Get an int version of the 2 digit year
year = int(sys.argv[2])
amount_counter = {}
if not all_time:
print "Trips this month:\n"
with open('trips_report.csv') as csvfile:
spamreader = csv.reader(csvfile)
row_idx = 0
for row in spamreader:
row_idx += 1
if row_idx < FIRST_ROW:
continue
date = row[DATE_INDEX]
date_parts = [int(y) for y in date.split('/')]
fare_month = date_parts[MONTH_INDEX]
fare_year = date_parts[YEAR_INDEX]
# If we are looking only at one month and it's the
# wrong month, continue on
if not all_time:
if month != fare_month or year != fare_year:
continue
email = row[EMAIL_INDEX]
fare = row[FARE_INDEX]
if not email in amount_counter:
amount_counter[email] = 0
amount_counter[email] += float(fare)
print date, email, fare
if not all_time:
print "\n\nSummary for %s/%s:\n" % (month, year)
else:
print "\n\nSummary:"
total = 0
for email, amount in amount_counter.iteritems():
print "%20s\t\t %s" % (email, amount)
total += amount
print "\nTotal: %f" % total
print "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment