diff --git a/README.md b/README.md index 97fd8d0..a413d74 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,20 @@ e-receipts, which is more than I can say for their competitor, Coles' FlyBuy pro UP_TOKEN=up:yeah:1234abcd... ``` 4. Look around & run some scripts, you crazy kids! +```commandline +$ python main.py + +{'date': '2020-12-31T10:13:58+11:00', + 'items': [{'amount': 0.94, + 'description': 'Tomato Truss Red', + 'quantity': None, + 'weight': 0.242}, + {'amount': 2.39, + 'description': 'WW Drought Relief Whole Milk 2L', + 'quantity': 1, + 'weight': None}, + ... +``` ## help wanted @@ -65,12 +79,15 @@ workflow, trying to see if it matches up with some common OAuth practice. Obtaining a user's `client_id` & `bearer token` via `accounts.woolworthsrewards.com.au/er-login/validate-user` from their `email` & `pass` is the ultimate goal. Any help would be great; I'd love to learn how that works. -## the graveyard of future ideas +## the graveyard of ideas * Support OpenBanking API - _aka_ support for all banks! * I noticed a purchase that I made with Westpac rather than Up, and after looking through Frollo & CDR I realised that many more banks had begun supporting the Open Banking initiative. * Unfortunately, despite its affiliation with _"Consumer Data Rights"_, the process of authenticating myself with these CDR data holders for my _own_ consumer data is a mystery to me. If you know, then please reach out to me. +* Talk to someone about Woolworths' API + * I tried reaching out to Woolworths to talk about their API: EverdayRewards support, the tech subsidiary managing + the program Quantium, even cold-messaged LinkedIn people associate with WooliesX. No luck. * Support 2Up * Please read [help wanted](#help-wanted) on how you can help push for API support of 2Up. \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/up_woolies/main.py b/src/up_woolies/main.py index 7ec2293..07311d0 100644 --- a/src/up_woolies/main.py +++ b/src/up_woolies/main.py @@ -1,12 +1,16 @@ import datetime +import json +from pprint import pprint import up import woolies def find_corresponding_up_transaction(woolies_transaction: woolies.Transaction) -> up.Transaction: + """ Returns corresponding Up Bank transaction from a Woolies transaction""" _up_description = 'Woolworths' # How Up manages human-readable merchant Id for Woolworths + # Request transactions within window of the Woolies transaction transaction_datetime = woolies_transaction.transaction_date for up_transactions in up_account.get_transactions(until=transaction_datetime + datetime.timedelta(seconds=10), since=transaction_datetime - datetime.timedelta(seconds=10)): @@ -35,13 +39,15 @@ def find_corresponding_up_transaction(woolies_transaction: woolies.Transaction) woolies_transaction.transaction_date) continue + # Find Up transaction try: up_transaction = find_corresponding_up_transaction(woolies_transaction) except FileNotFoundError: print("couldn't find an Up Banking transaction", woolies_transaction.transaction_date) continue + # Grab receipt and show woolies_receipt = woolies_transaction.get_receipt() - print("bingo", up_transaction.createdAt, woolies_receipt.json()) - print(1) + # Print it but make it pretty + pprint({'date': up_transaction.createdAt.astimezone().isoformat('T'), **json.loads(woolies_receipt.json())}) diff --git a/src/up_woolies/up.py b/src/up_woolies/up.py index 5ecc00a..8da40cb 100644 --- a/src/up_woolies/up.py +++ b/src/up_woolies/up.py @@ -74,13 +74,6 @@ def __init__(self, name: str): self.account = account self.transaction_url = account['relationships']['transactions']['links']['related'] - -class SpendingAccount(Account): - name = "Up Account" - - def __init__(self): - super().__init__(name=self.name) - def get_transactions(self, page_size: int = 10, since: datetime = None, @@ -100,6 +93,13 @@ def get_transactions(self, yield [Transaction.from_response(transaction) for transaction in response['data']] +class SpendingAccount(Account): + name = "Up Account" + + def __init__(self): + super().__init__(name=self.name) + + # diff --git a/src/up_woolies/woolies.py b/src/up_woolies/woolies.py index 2d69c7a..6ca7d96 100644 --- a/src/up_woolies/woolies.py +++ b/src/up_woolies/woolies.py @@ -36,7 +36,7 @@ class Purchase(BaseModel, extra=Extra.ignore): quantity: Optional[PositiveInt] = 1 weight: Optional[condecimal(gt=Decimal(0))] - # TODO parse description for weight e.g. {'description': 'Abbotts Vil Bakery Country Grains 800g'} + # TODO parse weight from description e.g. {'description': 'Abbotts Vil Bakery Country Grains 800g'} # TODO remove leading symbols from description e.g. {'description': '#Cadbury Bar Twirl 39g'} # TODO what if I purchase two weighted goods separately in one transaction; I went back to the deli for more olives?