Last active
December 10, 2015 23:19
-
-
Save kovshenin/4508727 to your computer and use it in GitHub Desktop.
When working with a full export it'll contain extra rows called Shopping Cart Item. This script removes such rows and copies the Item Titles of into the Item Title column of the original transaction row.
This file contains hidden or 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
""" | |
I hate PayPal. When working with a full export it'll contain extra rows called | |
Shopping Cart Item. This script removes such rows and copies the Item Titles of | |
into the Item Title column of the original transaction row. | |
Usage: | |
# python paypal-combine-rows.py input_file.csv > output_file.csv | |
""" | |
import csv | |
import sys | |
filename = sys.argv[1] | |
try: | |
reader = csv.reader(open(filename, 'rb'), delimiter=',', quotechar='"') | |
writer = csv.writer(sys.stdout, delimiter=',', quotechar='"') | |
except IOError as e: | |
print e | |
exit() | |
last_txn = '' | |
last_row = [] | |
# 0-based indices of columns. These may change when PayPal changes. | |
column_txn = 15 | |
column_item_title = 18 | |
for row in reader: | |
if row[column_txn] != last_txn: | |
if last_row: | |
last_row[column_item_title] = last_row[column_item_title].strip(',') # Trim the extra commas | |
writer.writerow(last_row) | |
last_row = row | |
else: | |
last_row[column_item_title] += ",%s" % row[column_item_title] # Replace Item Title with a real item title | |
last_txn = row[column_txn] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment