From ccfb4d65bd0778529cafbb3a2cbef2aef88a4e33 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 17 Feb 2022 22:03:48 +0000 Subject: [PATCH] Add certs folder to gitignore --- .gitignore | 1 + handler/transactions.py | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 35da2d8..df15f21 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ env/ keys/ handler/settings.ini handler/otp.key +handler/certs/ diff --git a/handler/transactions.py b/handler/transactions.py index 5487545..9f5ddb2 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -5,6 +5,8 @@ from twisted.logger import Logger from json import dumps from random import choices from string import ascii_uppercase +from elasticsearch import Elasticsearch +from datetime import datetime # Project imports from settings import settings @@ -23,6 +25,13 @@ class Transactions(object): Set the logger. """ self.log = Logger("transactions") + self.es = Elasticsearch( + f"https://{settings.ES.Host}:9200", + verify_certs=False, + basic_auth=(settings.ES.Username, settings.ES.Pass), + ssl_assert_fingerprint=("6b264fd2fd107d45652d8add1750a8a78f424542e13b056d0548173006260710"), + ca_certs="certs/ca.crt", + ) # TODO: write tests then refactor, this is terribly complicated! def transaction(self, data): @@ -466,11 +475,27 @@ class Transactions(object): price_usd = total_usd price_gbp = rates["GBP"] * total_usd - return ( + cast = ( (price_sek, price_usd, price_gbp), # Total prices in our 3 favourite currencies (total_usd_agora_xmr, total_usd_agora_btc), # Total USD balance in only Agora (total_xmr_agora, total_btc_agora), ) # Total XMR and BTC balance in Agora + self.write_to_es("total", cast) + return cast + + def write_to_es(self, msgtype, cast): + cast_remap = { + "type": msgtype, + "price_sek": cast[0][0], + "price_usd": cast[0][1], + "price_gbp": cast[0][2], + "total_usd_agora_xmr": cast[1][0], + "total_usd_agora_btc": cast[1][1], + "total_xmr_agora": cast[2][0], + "total_btc_agora": cast[2][1], + "ts": str(datetime.now().isoformat()), + } + self.es.index(index=settings.ES.Index, document=cast_remap) def get_remaining(self): """