Skip to content

Commit

Permalink
Brought the paypal script up to date again
Browse files Browse the repository at this point in the history
  • Loading branch information
mayhem committed Jan 1, 2024
1 parent 8258b2b commit a66da90
Showing 1 changed file with 15 additions and 37 deletions.
52 changes: 15 additions & 37 deletions misc/parse-paypal-us.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
import csv
from decimal import Decimal, InvalidOperation

# header

# "Date","Time","TimeZone","Name","Type","Status","Currency","Gross","Fee","Net","From Email Address","To Email Address","Transaction ID","Shipping Address","Address Status","Item Title","Item ID","Shipping and Handling Amount","Insurance Amount","Sales Tax","Option 1 Name","Option 1 Value","Option 2 Name","Option 2 Value","Reference Txn ID","Invoice Number","Custom Number","Quantity","Receipt ID","Balance","Address Line 1","Address Line 2/District/Neighborhood","Town/City","State/Province/Region/County/Territory/Prefecture/Republic","Zip/Postal Code","Country","Contact Phone Number","Subject","Note","Country Code","Balance Impact"

# conversion line
# "12/31/2017","14:50:41","PST","Mathias Kunter","General Payment","Completed","EUR","200.00","-7.75","192.25","mathiaskunter@gmail.com","paypal@metabrainz.org","3LW066840A4238521","Mathias, Kunter","Non-Confirmed","","","","","","","","","","","","","","","192.25","","","","","","","","","Magic MP3 Tagger November","","Credit"

def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
csv_reader = csv.reader(utf8_data, dialect=dialect, **kwargs)
for row in csv_reader:
Expand Down Expand Up @@ -48,6 +41,11 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
lines = []
reader = unicode_csv_reader(fp)
for line in reader:

# Filter out lines that complicate everything
if line[4] == "General Card Deposit":
continue

lines.append(line)

index = 1
Expand Down Expand Up @@ -80,51 +78,31 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
amount = gross

elif currency != 'USD':
print("transaction foreign")
# Received money in foreign currency
native = float(lines[index + 2][7].replace(",", ""))
foreign = -float(lines[index + 1][7].replace(",", ""))

#print "native %f, foreign %f" % (native, foreign)

ratio = native / foreign
#print "conversion rate: %f" % ratio

fee = float(fee) * ratio
fee = float(int(fee * 100)) / 100

amount = native - fee
#print "amount %f fee: %f" % (amount, fee)
foreign = float(lines[index + 2][7].replace(",", ""))
native = float(lines[index + 1][7].replace(",", ""))

index += 2
elif typ == "General Currency Conversion":
#print lines[index]
#print lines[index + 1]
#print lines[index + 2]

native = float(lines[index][7].replace(",", ""))
foreign = -float(lines[index + 1][7].replace(",", ""))
desc = lines[index + 2][3]

#print "native %f, foreign %f" % (native, foreign)
print("native %f, foreign %f" % (native, foreign))

ratio = native / foreign
#print "conversion rate: %f" % ratio
print("conversion rate: %f" % ratio)

fee = float(fee) * ratio
fee = float(fee) / ratio
fee = float(int(fee * 100)) / 100
net = native - fee

amount = native - fee
#print "amount %f fee: %f" % (amount, fee)
amount = native
print("amount %f fee: %f" % (amount, fee))

index += 2


desc = desc.replace(",", " ")
out.writerow([dat, desc, amount])

if balance is not None:
balance = balance + Decimal(str(net).replace(",", ""))
register.append("%s %-40s %10s %10s" % (dat, desc, str(net), str(balance)))
register.append("%s %-40s %10s %10s %10s" % (dat, desc, str(amount), str(fee), str(balance)))

desc = "PayPal Fee"
dat = fields[0]
Expand Down

0 comments on commit a66da90

Please sign in to comment.