forked from dvankley/firefly-plaid-connector-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plaidfireflyrulecreator.sh
77 lines (57 loc) · 2.48 KB
/
plaidfireflyrulecreator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
############
<<GuideDoc
- WARNING: ADDS A LOT OF RULES
- WARNING IDEAL PERHAPS ONLY FOR NEW INSTALLATIONS
- USE AT YOUR OWN RISK
This script facilitates a part of the integration of the firefly/plaid connector.
It will download the csv file from plaid.com at the start
It auto generates categories and budgets to match the
detailed and primary categories of the plaid category csv file.
1. Set your Token and Endpoint
2. Create A rule Group in firefly called: Plaid Tag to Category
3. chmod 755 this script
4. run the script
5. all new transactions from plaid should hit this rule and get put in a category and budget
On my pi this script takes like 15min to run.
GuideDoc
#########
#Set these two correctly
TOKEN="YOURTOKENGOESHERE"
ENDPOINT="http://localhost:9090/api/v1"
#Get the CSV file from plaid
curl -O https://plaid.com/documents/transactions-personal-finance-category-taxonomy.csv
### This Adds All the Rule Mapping
i=0
while read item; do
budget=$(echo $item | tr '[:upper:]' '[:lower:]' | cut -f 1 -d , | sed s/_/-/g)
detcat=$(echo $item | cut -f 2 -d , | tr '[:upper:]' '[:lower:]' | sed s/_/-/g | sed s/${budget}-//g)
curl -X POST \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-H 'accept: application/vnd.api+json' \
-d "{ \"name\": \"${budget}\", \"active\": true }" \
${ENDPOINT}/budgets
curl -X POST \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-H 'accept: application/vnd.api+json' \
-d "{ \"name\": \"${detcat}\", \"active\": true }" \
${ENDPOINT}/categories
curl -X POST \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-H 'accept: application/vnd.api+json' \
-d "{ \"title\": \"Plaid ${detcat} Mapping\", \"rule_group_title\": \"Plaid Tag to Category\", \"order\": ${i},\"trigger\": \"store-journal\", \"active\": true, \"strict\": true, \"stop_processing\": false, \
\"triggers\": [ \
{\"type\": \"has_no_category\", \"value\": \"true\", \"order\": 1, \"active\": true, \"stop_processing\": false}, \
{\"type\": \"tag_starts\", \"value\": \"plaid-detailed-cat-${detcat}\", \"order\": 2, \"active\": true, \"stop_processing\": false}
], \
\"actions\": [ \
{\"type\": \"set_category\", \"value\": \"${detcat}\", \"order\": 1, \"active\": true, \"stop_processing\": false}, \
{\"type\": \"set_budget\", \"value\": \"${budget}\", \"order\": 2, \"active\": true, \"stop_processing\": false} \
] \
}" \
${ENDPOINT}/rules
i=$((i+1))
done < transactions-personal-finance-category-taxonomy.csv