black & isort

This commit is contained in:
Gene Takavic
2022-08-14 10:52:58 -06:00
committed by Lee Salminen
parent 5af49e3801
commit 5b8d317441
6 changed files with 88 additions and 86 deletions
+22 -18
View File
@@ -1,13 +1,13 @@
from optparse import Option
from typing import List, Optional, Union
from lnbits.helpers import urlsafe_short_hash
from . import db
from .models import Card, CreateCardData, Hit
async def create_card(
data: CreateCardData, wallet_id: str
) -> Card:
async def create_card(data: CreateCardData, wallet_id: str) -> Card:
card_id = urlsafe_short_hash()
await db.execute(
"""
@@ -38,6 +38,7 @@ async def create_card(
assert card, "Newly created card couldn't be retrieved"
return card
async def update_card(card_id: str, **kwargs) -> Optional[Card]:
if "is_unique" in kwargs:
kwargs["is_unique"] = int(kwargs["is_unique"])
@@ -46,11 +47,10 @@ async def update_card(card_id: str, **kwargs) -> Optional[Card]:
f"UPDATE boltcards.cards SET {q} WHERE id = ?",
(*kwargs.values(), card_id),
)
row = await db.fetchone(
"SELECT * FROM boltcards.cards WHERE id = ?", (card_id,)
)
row = await db.fetchone("SELECT * FROM boltcards.cards WHERE id = ?", (card_id,))
return Card(**row) if row else None
async def get_cards(wallet_ids: Union[str, List[str]]) -> List[Card]:
if isinstance(wallet_ids, str):
wallet_ids = [wallet_ids]
@@ -62,17 +62,20 @@ async def get_cards(wallet_ids: Union[str, List[str]]) -> List[Card]:
return [Card(**row) for row in rows]
async def get_all_cards() -> List[Card]:
rows = await db.fetchall(
f"SELECT * FROM boltcards.cards"
)
rows = await db.fetchall(f"SELECT * FROM boltcards.cards")
return [Card(**row) for row in rows]
async def get_card(card_id: str, id_is_uid: bool=False) -> Optional[Card]:
sql = "SELECT * FROM boltcards.cards WHERE {} = ?".format("uid" if id_is_uid else "id")
async def get_card(card_id: str, id_is_uid: bool = False) -> Optional[Card]:
sql = "SELECT * FROM boltcards.cards WHERE {} = ?".format(
"uid" if id_is_uid else "id"
)
row = await db.fetchone(
sql, card_id,
sql,
card_id,
)
if not row:
return None
@@ -81,19 +84,20 @@ async def get_card(card_id: str, id_is_uid: bool=False) -> Optional[Card]:
return Card.parse_obj(card)
async def delete_card(card_id: str) -> None:
await db.execute("DELETE FROM boltcards.cards WHERE id = ?", (card_id,))
async def update_card_counter(counter: int, id: str):
await db.execute(
"UPDATE boltcards.cards SET counter = ? WHERE id = ?",
(counter, id),
)
async def get_hit(hit_id: str) -> Optional[Hit]:
row = await db.fetchone(
f"SELECT * FROM boltcards.hits WHERE id = ?", (hit_id)
)
row = await db.fetchone(f"SELECT * FROM boltcards.hits WHERE id = ?", (hit_id))
if not row:
return None
@@ -101,6 +105,7 @@ async def get_hit(hit_id: str) -> Optional[Hit]:
return Hit.parse_obj(hit)
async def get_hits(cards_ids: Union[str, List[str]]) -> List[Hit]:
q = ",".join(["?"] * len(cards_ids))
rows = await db.fetchall(
@@ -109,9 +114,8 @@ async def get_hits(cards_ids: Union[str, List[str]]) -> List[Hit]:
return [Hit(**row) for row in rows]
async def create_hit(
card_id, ip, useragent, old_ctr, new_ctr
) -> Hit:
async def create_hit(card_id, ip, useragent, old_ctr, new_ctr) -> Hit:
hit_id = urlsafe_short_hash()
await db.execute(
"""