-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
34 lines (27 loc) · 1.01 KB
/
main.py
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
import json
import requests
from datetime import date
with open('./config.json', 'r') as f:
config = json.load(f)
headers = {"Authorization": "Bearer " + config["secret"]}
base_url = "https://api.youneedabudget.com/v1/budgets/" +config["budget"] + '/'
current_balance = float(requests.get(
base_url + "accounts/" + config["account"],
headers=headers).json()["data"]["account"]["balance"])
conversion_rate = float(requests.get("https://blockchain.info/ticker").json()["USD"]["15m"])
new_balance = conversion_rate * float(config["holdings"]) * 1000
data = {
"transaction": {
"account_id": config["account"],
"date": date.today().isoformat(),
"amount": int(new_balance-current_balance),
"payee_name": "Coal Correction",
"category_id": config["category"],
"memo": "",
"cleared": "reconciled",
"approved": True,
"flag_color": "blue"
}
}
response = requests.post(base_url + "transactions", json=data, headers=headers)
print(response.json())