add disabled state

This commit is contained in:
null
2024-03-07 20:07:39 +01:00
parent 5bb4da7499
commit 2c96653753
3 changed files with 34 additions and 4 deletions
+10 -1
View File
@@ -5,4 +5,13 @@ class Condition:
id: str
symbol: str
condition: str
value: float
value: float
disabled: bool
@staticmethod
def lower_than(value: float, lastPrice: float):
return value < lastPrice
@staticmethod
def greater_than(value: float, lastPrice: float):
return value < lastPrice
+14 -3
View File
@@ -1,5 +1,6 @@
import os
from typing import Callable
from flask import jsonify
from rethinkdb import RethinkDB
from .Condition import Condition
@@ -33,16 +34,26 @@ def fetch_conditions() -> list[Condition]:
conditions: list[Condition] = list()
class DbConnector:
@staticmethod
def watch_conditions(callback: Callable[[Condition], None]):
global conditions
conditions = fetch_conditions()
for cond in conditions:
callback(cond)
if not cond.disabled:
callback(cond)
feed = r.table(TABLE_NAME).changes().run(get_connection())
for change in feed:
if change['new_val'] and not change['old_val']: # New symbol added
cond: Condition = change['new_val']
cond = Condition(**change['new_val'])
if not cond.disabled:
callback(cond)
@staticmethod
def disable_condition(condition_id: str):
cursor = r.table(TABLE_NAME).get(condition_id).run(get_connection())
json = jsonify(cursor)
json.disabled = True
r.table(TABLE_NAME).get(condition_id).update(json).run(get_connection())