From a66da90d55b700190df4cbfcb18fa6793a7b89ff Mon Sep 17 00:00:00 2001 From: Robert Kaye Date: Mon, 1 Jan 2024 18:36:40 +0100 Subject: [PATCH] Brought the paypal script up to date again --- misc/parse-paypal-us.py | 52 ++++++++++++----------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) diff --git a/misc/parse-paypal-us.py b/misc/parse-paypal-us.py index 75653458..30f69633 100755 --- a/misc/parse-paypal-us.py +++ b/misc/parse-paypal-us.py @@ -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: @@ -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 @@ -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]