Skip to content

Commit

Permalink
Merge pull request #3 from shayki5/daniel-hauser-main
Browse files Browse the repository at this point in the history
sync upstream
  • Loading branch information
shayki5 authored Apr 17, 2024
2 parents d98aceb + fbbbc9e commit bdd03e8
Show file tree
Hide file tree
Showing 22 changed files with 2,168 additions and 2,189 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ on:
workflow_dispatch:
push:
branches: ["main"]
paths-ignore:
- ".github/**"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
Expand All @@ -20,18 +17,21 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- id: normalize-repository-name
run: echo "repository=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT

- name: Log in to the Container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
tags: ${{ env.REGISTRY }}/${{ steps.normalize-repository-name.outputs.repository }}:latest
21 changes: 17 additions & 4 deletions .github/workflows/scrape.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ on:
schedule:
- cron: "00 06 * * *"
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}:latest
REGISTRY: ghcr.io
jobs:
scrape:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.1

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11.4"

- name: Check if first day of the month
run: |
current_date=$(date +"%Y-%m-%d")
Expand All @@ -49,8 +51,13 @@ jobs:
fi
env:
GOOGLE_JSON: ${{ secrets.GOOGLE_JSON }}

- id: normalize-repository-name
run: echo "repository=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT

- name: Pull image
run: docker pull $IMAGE_NAME
run: docker pull ${{ env.REGISTRY }}/${{ steps.normalize-repository-name.outputs.repository }}:latest

- name: Run scraper
run: docker run --rm
-e DEBUG
Expand All @@ -72,7 +79,10 @@ jobs:
-e AZURE_APP_ID
-e AZURE_APP_KEY
-e SCRAPE_FROM_BEGINNING_OF_MONTH
$IMAGE_NAME
-e YNAB_TOKEN
-e YNAB_BUDGET_ID
-e YNAB_ACCOUNTS
${{ env.REGISTRY }}/${{ steps.normalize-repository-name.outputs.repository }}:latest
env:
DEBUG: ""
TZ: "UTC"
Expand All @@ -93,6 +103,9 @@ jobs:
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_APP_ID: ${{ secrets.AZURE_APP_ID }}
AZURE_APP_KEY: ${{ secrets.AZURE_APP_KEY }}
YNAB_TOKEN: ${{ secrets.YNAB_TOKEN }}
YNAB_BUDGET_ID: ${{ secrets.YNAB_BUDGET_ID }}
YNAB_ACCOUNTS: ${{ secrets.YNAB_ACCOUNTS }}

- name: Update categories
run: |
Expand All @@ -111,4 +124,4 @@ jobs:
uses: fjogeleit/http-request-action@v1
with:
url: "${{ secrets.UPDATE_WEB_HOOK }}"
method: "GET"
method: "GET"
13 changes: 7 additions & 6 deletions .github/workflows/verify-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [16.x, latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm test
- run: npm run lint
- run: npm run test
- run: npm run build
build_image:
runs-on: ubuntu-latest
Expand All @@ -36,10 +37,10 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Build Docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
push: false
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cSpell.words": ["Kusto", "moneyman", "MULTIJSON", "nektos", "txns"],
"cSpell.words": ["Kusto", "moneyman", "MULTIJSON", "nektos", "txns", "ynab"],
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": "file:///workspaces/money/.github/workflows/build.yml"
}
Expand Down
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Internally we use [israeli-bank-scrapers](https://github.com/eshaham/israeli-ban

## Why?

Having all your data in one place lets you view all of your expenses in a beautiful dashboard like [Google Data Studio](https://datastudio.google.com), [Azure Data Explorer dashboards](https://docs.microsoft.com/en-us/azure/data-explorer/azure-data-explorer-dashboards) and [Microsoft Power BI](https://powerbi.microsoft.com/)
Having all your data in one place lets you view all of your expenses in a beautiful dashboard like [Google Data Studio](https://datastudio.google.com), [Azure Data Explorer dashboards](https://docs.microsoft.com/en-us/azure/data-explorer/azure-data-explorer-dashboards), [Microsoft Power BI](https://powerbi.microsoft.com/) and [YNAB](https://www.ynab.com/).

## Important notes

Expand All @@ -24,7 +24,7 @@ By using moneyman, you acknowledge that you are taking full responsibility for t

## How to run

### Cloud
### Cloud (GitHub Actions)

Moneyman can be configured to periodically run automatically, using the [`scrape`](./.github/workflows/scrape.yml) github workflow.

Expand All @@ -39,7 +39,8 @@ Since logs are public for public repos, most logs are off by default and the pro
1. [`ACCOUNTS_JSON`](#add-accounts-and-scrape) - So moneyman can login to your accounts
2. [`TELEGRAM_API_[KEY, CHAT_ID]`](#get-notified-in-telegram) - So moneyman can send private logs and errors
3. The environment variables of the storage you want to use
3. Wait for the workflow to be triggered by github
3. Build and upload the docker image using the "Run workflow" button in [workflows/build.yml](../../actions/workflows/build.yml)
4. Wait for the [scrape workflow](../../actions/workflows/scrape.yml) to be triggered by github

### locally

Expand Down Expand Up @@ -89,7 +90,7 @@ Example:

| env variable name | default | description |
| -------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------ |
| `ACCOUNTS_TO_SCRAPE` | `[]` | A comma separated list of providers to take from `ACCOUNTS_JSON`. if empty, all accounts will be used |
| `ACCOUNTS_TO_SCRAPE` | `""` | A comma separated list of providers to take from `ACCOUNTS_JSON`. if empty, all accounts will be used |
| `DAYS_BACK` | `10` | The amount of days back to scrape |
| `TZ` | `'Asia/Jerusalem'` | A timezone for the process - used for the formatting of the timestamp |
| `FUTURE_MONTHS` | `1` | The amount of months that will be scrapped in the future, starting from the day calculated using `DAYS_BACK` |
Expand Down Expand Up @@ -181,3 +182,27 @@ Use the following env vars to setup:
| `GOOGLE_SERVICE_ACCOUNT_EMAIL` | The service account's email address |
| `GOOGLE_SHEET_ID` | The id of the spreadsheet you shared with the service account |
| `WORKSHEET_NAME` | The name of the sheet you want to add the transactions to |

### Export to YNAB (YouNeedABudget)

To export your transactions directly to `YNAB` you need to use the following environment variables to setup:
| env variable name | description |
| ------------------------------------ | ------------------------------------------------------------- |
| `YNAB_TOKEN` | The `YNAB` access token. Check [YNAB documentation](https://api.ynab.com/#authentication) about how to obtain it |
| `YNAB_BUDGET_ID` | The `YNAB` budget ID where you want to import the data. You can obtain it opening [YNAB application](https://app.ynab.com/) on a browser and taking the budget `UUID` in the `URL` |
| `YNAB_ACCOUNTS` | A key-value list to correlate each account with the `YNAB` account `UUID` |

#### YNAB_ACCOUNTS

A `JSON` key-value pair structure representing a mapping between two identifiers. The `key` represent the account ID as is understood by moneyman and the `value` it's the `UUID` visible in the YNAB URL when an account is selected.

For example, in the URL:
`https://app.ynab.com/22aa9fcd-93a9-47e9-8ff6-33036b7c6242/accounts/ba2dd3a9-b7d4-46d6-8413-8327203e2b82` the account UUID is the second `UUID`.

Example:

```json
{
"5897": "ba2dd3a9-b7d4-46d6-8413-8327203e2b82"
}
```
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
export default {
preset: "ts-jest",
testEnvironment: "node",
rootDir: "./src",
};
Loading

0 comments on commit bdd03e8

Please sign in to comment.