Skip to content

Commit

Permalink
Parses everything!
Browse files Browse the repository at this point in the history
  • Loading branch information
mayhem committed Sep 24, 2024
1 parent 07338ea commit 8d5bcde
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions misc/parse-paypal-us.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,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] in ("General Card Deposit", "Account Hold for Open Authorization", "Reversal of General Account Hold"):
continue

if line[5] != 'Completed':
continue

lines.append(line)

print("DATE NAME GROSS FEE PP_BAL BALANCE")

index = 0
index = 1
register = []
balance = None
while True:
Expand Down Expand Up @@ -96,6 +88,12 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
usd_fee = Decimal(fee) * exchange_rate
usd_fee = Decimal(int(usd_fee * 100)) / 100
gross = usd - usd_fee
fee = usd_fee
net = usd

if typ == "Express Checkout Payment":
gross = -gross
net = -net

print(" foreign: ", foreign)
print(" foreign fee: ", fee)
Expand All @@ -104,18 +102,17 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
print(" gross: ", gross)
print("exchange rate: ", exchange_rate)

if typ == "Express Checkout Payment":
gross = -gross

fee = usd_fee
net = usd
# Get the correct balance, because WTF paypal.
pp_balance = Decimal(lines[index + 2][29].replace(",", ""))

# The balance for express checkout are zero. thanks paypal.
if pp_balance == Decimal(0.0):
print("Balance fix!")
pp_balance = balance - usd
print("balance: %s gross: %s" % (str(balance), str(gross)))
pp_balance = balance + gross

print("Balance: ", balance)

index += 2
else:
Expand All @@ -136,10 +133,10 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
balance = balance + net
if balance != pp_balance:
print(" discrepancy: ", (pp_balance - balance))
print("%s %-40s %10s %10s %10s %10s" % (dat, desc, str(gross), str(fee),
str(pp_balance), str(balance)))
sys.exit(-1)

print(desc)

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

Expand Down

0 comments on commit 8d5bcde

Please sign in to comment.