Skip to content

Commit

Permalink
refactor: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
MattTimms committed Jul 24, 2021
1 parent ec1dd03 commit 46b3260
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Empty file removed src/__init__.py
Empty file.
10 changes: 8 additions & 2 deletions src/up_woolies/main.py
Original file line number Diff line number Diff line change
@@ -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)):
Expand Down Expand Up @@ -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())})
14 changes: 7 additions & 7 deletions src/up_woolies/up.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)


#


Expand Down
2 changes: 1 addition & 1 deletion src/up_woolies/woolies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down

0 comments on commit 46b3260

Please sign in to comment.