import api_settings from ynab.rest import ApiException from pprint import pprint import paho.mqtt.client as mqtt Broker = api_settings.broker # Configure API key authorization: bearer configuration = ynab.Configuration() configuration.api_key['Authorization'] = api_settings.api_key # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed configuration.api_key_prefix['Authorization'] = 'Bearer' # create an instance of the API class api_instance = ynab.CategoriesApi(ynab.ApiClient(configuration)) try: client = mqtt.Client() client.connect(Broker) for item in api_settings.balances: # print(item) api_response = api_instance.get_category_by_id(api_settings.budget_id, item['category_id']) id = api_response.data.category.id name = item['category_name'].replace(' ','_') topic = "ynab/category/{0}/{1}/{2}".format(id,name,'balance' ) info = client.publish(topic, api_response.data.category.balance/1000, retain=False) info.wait_for_publish() time.sleep(0.5)
d['Name'] = accounts[account_idx]['Name'] d['account'] = accounts[account_idx]['account'] if len(reference) > 0 and hasattr(reference[0], 'transfer_payee_id'): d['payee_id'] = reference[0].transfer_payee_id else: d['payee_id'] = None return d # Configure API key authorization: bearer configuration = ynab.Configuration() configuration.api_key['Authorization'] = api_settings.api_key configuration.api_key_prefix['Authorization'] = 'Bearer' # create an instance of the API class api_instance = ynab.TransactionsApi(ynab.ApiClient(configuration)) api_accounts = ynab.AccountsApi(ynab.ApiClient(configuration)) #SBanken auth http_session = create_authenticated_http_session(api_settings.CLIENTID, api_settings.SECRET) today = datetime.date.today() endDate = today startDate = today - datetime.timedelta(8) # Last 8 days # Get the transactions for all accounts accounts = [] for mapping in api_settings.mapping: accounts.append(get_transactions_period( http_session, api_settings.CUSTOMERID, mapping['ID'],
import os from datetime import datetime # from urllib.parse import urljoin # import os # import sys # # insert at 1, 0 is the script path (or '' in REPL) # sys.path.insert(1, urljoin(os.getcwd(), 'config')) # from config import ynabConfig import settings configuration = ynab.Configuration() configuration.api_key['Authorization'] = settings.YNAB[ 'APIKEY'] # api_key is a token you get in Developer settings # # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed configuration.api_key_prefix['Authorization'] = 'Bearer' api_instance = ynab.TransactionsApi(ynab.ApiClient(configuration)) class Ynab(): def sayHello(self): print("hello") def loadJSONfromFile(self, file): # will load JSON from a JSON file with open(file) as f: r = json.load(f) return r def JSON_OPS_2_YNAB(self, src): # will post json bank transactions to YNAB # while True: # stuff()