class DBCandleManager: def __init__(self, path, table): self.db = Connector(path) self.table = table self.db.connect() def create_table(self): self.db.create_table(f'''CREATE TABLE IF NOT EXISTS {self.table}( id INTEGER PRIMARY KEY, date INTEGER NOT NULL UNIQUE, open REAL NOT NULL, high REAL NOT NULL, low REAL NOT NULL, close REAL NOT NULL, volume REAL NOT NULL);''') def insert(self, candle): self.db.insert( f'INSERT INTO {self.table} (date,open,high,low,close,volume) VALUES({candle[0]},{candle[1]},{candle[2]},{candle[3]},{candle[4]},{candle[5]});' ) def get_last_candle(self): self.create_table() result = self.db.select( f'SELECT * FROM {self.table} ORDER BY date DESC LIMIT 1') if len(result) > 0: return result[0] else: return 'null' def get_first_candle(self): self.create_table() result = self.db.select( f'SELECT * FROM {self.table} ORDER BY date ASC LIMIT 1') if len(result) > 0: return result[0] else: return 'null' def get_candles_cursor(self, start, offset): start = datetime.fromtimestamp(start / 1e3) - timedelta(minutes=offset) start = int(datetime.timestamp(start)) * 1e3 self.create_table() results = self.db.select( f'SELECT * FROM {self.table} WHERE date > {start} ORDER BY date LIMIT {offset}' ) return results def get_candles(self): self.create_table() results = self.db.select(f'SELECT * FROM {self.table}') return results
import asyncio import datetime import aiohttp from prometheus_client import CollectorRegistry from collections import deque, defaultdict import discord from discord import Intents from discord.ext.commands import AutoShardedBot from Bot import Handlers from Utils import Utils from Database import Connector, DBUtils db = Connector.Database() def prefix_callable(bot, message): prefixes = [f"<@!{bot.user.id}> ", f"<@{bot.user.id}> "] if message.guild is None: prefixes.append("+") elif bot.READY: try: prefix = DBUtils.get(db.configs, "guildId", f"{message.guild.id}", "prefix") if prefix is not None: prefixes.append(prefix) else: prefixes.append("+") except Exception: prefixes.append("+")
def __init__(self, path, table): self.db = Connector(path) self.table = table self.db.connect()