Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,507 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Amonzo Expronzo | ||
|
||
## what is?? | ||
|
||
this is for chee to make spending money on their American Express card feel like spending money. | ||
|
||
i run it on a loop on my server. | ||
|
||
it goes like this: | ||
|
||
* get the amount of money in my `amex` pot from monzo | ||
* log onto the amex website w/ puppeteer | ||
- get current available balance | ||
- take that off the total available credit to get how much has probably been spent | ||
* if there is more spent than in the `amex`pot, top up the `amex` pot from current account | ||
* send an item into the monzo feed (which sends a push notification) | ||
|
||
## how to use | ||
|
||
basically don't? and if you do, leave me alone. | ||
|
||
that being said: | ||
|
||
the script `run` is how you get it started. you'll need to run it in the directory where `get-balance.js` is, because it expects it to be there and i haven't used `dirname $(readlink -f $0)`. run it in a loop. i run it every minute on a server. you'll need to set some env vars: | ||
|
||
### environment variables | ||
|
||
name | description | ||
------- | --------------- | ||
pot_id | the pot id you will be keeping your card-paying-off money in (find it via [monzo api](https://docs.monzo.com/#pots)) | ||
access_token | your [monzo access token](http://developers.monzo.com) | ||
account_id | your monzo account id | ||
amex_user | your amex username | ||
amex_pass | your amex password | ||
available_credit | the total available credit in your amex account | ||
|
||
## disclaimer | ||
|
||
* don't rely on this | ||
* don't expect it to work tomorrow | ||
* don't @ me | ||
* pull requests welcome | ||
* actually you can @ me sorry for being defensive |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
let pup = require("puppeteer") | ||
|
||
;(async function() { | ||
let puppy = await pup.launch({ | ||
headless: !false, | ||
args: ["--no-sandbox"], | ||
}) | ||
|
||
let bone = await puppy.newPage() | ||
|
||
await bone.goto( | ||
"https://global.americanexpress.com/login/en-GB?noRedirect=true&DestPage=%2Fdashboard", | ||
{waitUntil: "networkidle2"} | ||
) | ||
|
||
await bone.waitForSelector(".eliloUserId input") | ||
await bone.type(".eliloUserId input", process.env.amex_user) | ||
await bone.waitForSelector(".eliloPassword input") | ||
await bone.type(".eliloPassword input", process.env.amex_pass) | ||
// ignore the next three lines | ||
await bone.mouse.move(10, 20) | ||
await bone.mouse.down() | ||
await bone.mouse.up() | ||
await bone.click("[type=submit]") | ||
await bone.waitForNavigation() | ||
await bone.waitForSelector(".summary-container") | ||
await bone.waitForSelector( | ||
"ul .undefined:nth-child(1) .value-link-inline-block" | ||
) | ||
|
||
let balanceElement = await bone.$( | ||
"ul .undefined:nth-child(1) .value-link-inline-block .data-value" | ||
) | ||
|
||
let availableBalance = await bone.evaluate( | ||
element => element.textContent, | ||
balanceElement | ||
) | ||
|
||
let availableCredit = Number(process.env.available_credit || 3000) | ||
|
||
let currentBalance = | ||
availableCredit - parseFloat(availableBalance.replace(/[^.0-9]/g, "")) | ||
|
||
console.log(currentBalance) | ||
|
||
await puppy.close() | ||
})().catch(x => { | ||
console.error(x) | ||
process.exit(1) | ||
}) |
Oops, something went wrong.