Bug fixes

Based on the first day of dogfooding for myself
This commit is contained in:
2024-11-30 23:42:35 -08:00
parent 5db4e76de8
commit a067953467
7 changed files with 36 additions and 39 deletions

View File

@@ -4,6 +4,7 @@ from aiodynamo.client import Table
from aiodynamo.errors import ItemNotFound
from aiodynamo.expressions import F
from token_bot.persistant_database import AlertType
from token_bot.token_database.flavor import Flavor
from token_bot.token_database.region import Region
import token_bot.persistant_database as pdb
@@ -70,10 +71,10 @@ class Alert:
return self.alert_type == other.alert_type and self.flavor == other.flavor and self.price == other.price
def to_human_string(self):
if self.alert_type.SPECIFIC_PRICE:
if self.alert_type == AlertType.SPECIFIC_PRICE:
raise NotImplementedError
else:
return f"\n|Region: {self.region.value.upper()}\tFlavor: {self.flavor.value.upper()}\tAlert: {self.alert_type.name.lower()}|"
return f"\n|\tRegion: {self.region.value.upper()}\tFlavor: {self.flavor.name.lower()}\tAlert: {self.alert_type.name.lower()}\t|"
async def _lazy_load(self, table: Table, consistent: bool = False) -> None:
if consistent or not self._loaded:
@@ -91,7 +92,7 @@ class Alert:
)
async def put(self, table: Table) -> None:
user_ids = [user.user_id for user in self._users]
user_ids = [str(user.user_id) for user in self._users]
await table.put_item(
item={
self.primary_key_name: self.primary_key,
@@ -108,10 +109,9 @@ class Alert:
)
except ItemNotFound:
return False
if 'Item' in response:
self._users = [pdb.User(int(user_id)) for user_id in response['Item']['users']['NS']]
self._loaded = True
return True
self._users = [pdb.User(int(user_id)) for user_id in response['users']]
self._loaded = True
return True
async def get_users(self, table: Table, consistent: bool = False) -> List[pdb.User]:
await self._lazy_load(table, consistent=consistent)