Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
# Created by Andrew Wooster on 2009-11-04.
# Copyright Planetary Scale LLC 2009.
# Released under the MIT License.
import sys
"""
Takes iPhone app revenue data and combines sales from all apps into daily combined
values.
Steps to use:
1. Export your data from AppViz with the "Revenue by Day" format.
2. ./convert_sales.py revenue.txt > revenue.csv
3. Do what you will.
"""
def main(args):
filename = args[1]
contents = open(filename).read()
carryover = []
new_lines = []
for line in contents.splitlines():
if '$' not in line:
new_lines.append(line)
continue
parts = line.split('\t')
parts[0] = parts[0].replace(' 00:00:00 +0000', '')
parts[2] = "Combined"
parts[3] = parts[3].replace('$', '')
if len(carryover) and parts[0] != carryover[0]:
new_lines.append('\t'.join(carryover))
carryover = parts
elif len(carryover):
carryover[3] = "%.2f" % (float(carryover[3]) + float(parts[3]))
else:
carryover = parts
if len(carryover):
new_lines.append('\t'.join(carryover))
for line in new_lines:
print line
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment