MVP
This commit is contained in:
@ -1 +1,2 @@
|
||||
from .singleton import Singleton
|
||||
from .singleton import Singleton
|
||||
from .nft_util import get_image
|
||||
|
17
util/nft_util.py
Normal file
17
util/nft_util.py
Normal file
@ -0,0 +1,17 @@
|
||||
import base64
|
||||
import logging
|
||||
import os
|
||||
|
||||
from sphinx.util import requests
|
||||
|
||||
from config import Config
|
||||
|
||||
|
||||
def get_image(user_id: int) -> str:
|
||||
path = os.path.join(Config().TMP_DIR, f"{user_id}.png")
|
||||
if not os.path.exists(path):
|
||||
logging.warn(f"Getting new image for {user_id}!")
|
||||
req = requests.get(f"{Config().NFT_SVC_ADDR}/getImage").json()
|
||||
with open(path, "wb") as f:
|
||||
f.write(base64.b64decode(req["image"]))
|
||||
return path
|
18
util/redis_db.py
Normal file
18
util/redis_db.py
Normal file
@ -0,0 +1,18 @@
|
||||
from config import Config
|
||||
from util import Singleton
|
||||
import redis
|
||||
|
||||
|
||||
class RedisDB(metaclass=Singleton):
|
||||
def __init__(self):
|
||||
self.r = redis.Redis(Config().REDIS_ADDR)
|
||||
|
||||
def get_state(self, user_id: int) -> int:
|
||||
db_ret = self.r.get(f"{user_id}_test_state")
|
||||
return int(db_ret.decode()) if db_ret else None
|
||||
|
||||
def set_state(self, user_id: int, state: int):
|
||||
self.r.set(f"{user_id}_test_state", str(state))
|
||||
|
||||
def del_state(self, user_id):
|
||||
self.r.delete(f"{user_id}_test_state")
|
Reference in New Issue
Block a user