Created
December 20, 2021 05:50
-
-
Save baileywickham/edeffbaab964adc7629ec9931a51e215 to your computer and use it in GitHub Desktop.
Calculate the difference between two venmo users
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
import csv | |
import sys | |
me = '' | |
them = '' | |
paid_to_me = 0 | |
paid_to_them = 0 | |
payment_from_them = 0 | |
payment_to_them = 0 | |
with open(sys.argv[1], 'r') as f: | |
r = csv.reader(f) | |
for line in r: | |
is_payment = True if line[3] == 'Payment' else False | |
is_charge = True if line[3] == 'Charge' else False | |
frm = line[6] | |
to = line[7] | |
if not (is_payment or is_charge): | |
continue | |
amount = float(line[8][3:]) | |
if is_payment and frm == them and to == me: | |
payment_from_them += 1 | |
paid_to_me += amount | |
if is_payment and frm == me and to == them: | |
payment_to_them += 1 | |
paid_to_them += amount | |
if is_charge and frm == them and to == me: | |
paid_to_them += amount | |
if is_charge and frm == me and to == them: | |
paid_to_me += amount | |
print(f'''{me} paid {them}: {paid_to_them}. Number of times: {payment_to_them} | |
{them} paid {me}: {paid_to_me}. Number of times: {payment_from_them} | |
difference: {max(paid_to_them, paid_to_me) - min(paid_to_me, paid_to_them)}, total payments: {payment_from_them + payment_to_them}''') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment