def fetch(self, *options, **kwargs): with Database() as db: db._check_if_opened() with open(self.file_name, "r") as file: sql_query = file.read() if options: sql_query = sql_query.format(*options) db.cursor.execute(sql_query) if kwargs.get("fetch_results", True): results = db.cursor.fetchall() return results return []
def __init__(self, *args, **kwargs): logger.info("Starting up...") intents = Intents.all() super().__init__( command_prefix="!", intents=intents, help_command=Help(), *args, **kwargs ) self.db: Database = Database()
def __init__(self, *args, **kwargs): logger.info("Starting up...") intents = Intents.all() super().__init__(command_prefix=">", intents=intents, allowed_mentions=AllowedMentions(roles=False, everyone=False), activity=Game(name="Annihilating Tomatos!"), *args, **kwargs) self.db: Database = Database()
def __init__(self, *args, **kwargs): logger.info("Starting up...") intents = Intents.all() super().__init__(command_prefix=".", intents=intents, help_command=Help(), allowed_mentions=AllowedMentions(replied_user=False), *args, **kwargs) self.db: Database = Database() self.sess: ClientSession = None
def __init__(self, *args, **kwargs): logger.info("Starting up...") intents = Intents.all() super().__init__( command_prefix="!", intents=intents, help_command=Help(), allowed_mentions=AllowedMentions(roles=False, everyone=False), *args, **kwargs ) self.db: Database = Database()
def __init__(self, *args, **kwargs): logger.info("Starting up...") intents = Intents( messages=True, guilds=True, members=True, ) super().__init__(command_prefix="z!", intents=intents, help_command=None, allowed_mentions=AllowedMentions(roles=False, everyone=False), activity=Game(name="with metrics"), *args, **kwargs) self.db: Database = Database()
def __init__(self, *args, **kwargs): logger.info("Starting up...") self.start_time = time() intents = Intents.all() super().__init__(command_prefix=self.get_prefix, intents=intents, help_command=Help(), allowed_mentions=AllowedMentions( roles=False, everyone=False, replied_user=False, ), *args, **kwargs) self.db: Database = Database() self.http_session: ClientSession = None self.prefixes = TimedCache(30)
seed=RAND_SEED) print('Total sentences: ', len(raw_sentences)) data = RatioChanger.partition(RatioChanger.get_map(raw_sentences)) pos_sentences = [] neg_sentences = [] for dtype in DIVISION[0]: neg_sentences += data[dtype] for dtype in DIVISION[1]: pos_sentences += data[dtype] # print('Positive sentences ', len(pos_sentences)) # print('Negative sentences ', len(neg_sentences)) # Database.dump_example(pos_sentences, neg_sentences, STOP_WORDS, FEATURE_MODE) pos, neg = Database.load_example(FEATURE_MODE) if FEATURE_MODE == 'word2vec': avg = lambda sentence: sum([item.vector for item in sentence]) / len(sentence) pos = [avg(sentence) for sentence in pos if len(sentence)] neg = [avg(sentence) for sentence in neg if len(sentence)] test_data, test_label, train_data, train_label, evaluate_data, evaluate_label = \ Dataset(list(pos), list(neg)).split(0.6, 0.35, RAND_SEED) test_data, test_label = change_inner_ratio(test_data, test_label, CHANGE_RATIO_MODE, RAND_SEED, RATIO) train_data, train_label = change_inner_ratio(train_data, train_label, CHANGE_RATIO_MODE, RAND_SEED, RATIO) evaluate_data, evaluate_label = change_inner_ratio(evaluate_data, evaluate_label,
from src.utils.ids import IDGenerator from src.utils.database import Database from src.routing import frontend_router, api_router if not getenv("IN_DOCKER"): load_dotenv() app = FastAPI(docs_url=None, redoc_url=None, apoenapi_url=None) app.mount("/static", StaticFiles(directory="static"), "static") app.include_router(frontend_router) app.include_router(api_router) templates = Jinja2Templates(directory="templates") session = ClientSession() db = Database() ids = IDGenerator() @app.on_event("startup") async def on_startup() -> None: """Connect the database on startup.""" await db.ainit() @app.middleware("http") async def attach(request: Request, call_next) -> Response: """Attach the ClientSession, database and idgen to requests.""" request.state.session = session request.state.db = db request.state.ids = ids