Skip to content

Instantly share code, notes, and snippets.

@wooster
Created November 4, 2009 08:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wooster/225897 to your computer and use it in GitHub Desktop.
#!/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