def main(): parser = argparse.ArgumentParser() parser.add_argument('-c', '--currency', required=True) parser.add_argument('-p', '--period', type=int, required=True, choices=[60, 300, 600]) args = parser.parse_args() poloniex = Poloniex(args.currency, args.period) count = 0 while(True): date = datetime.now() open = poloniex.get_field('last') close = poloniex.get_field('last') high = poloniex.get_field('high24hr') low = poloniex.get_field('low24hr') db = Database() db.create(currency=args.currency, period=args.period, date_initial=date, open_candle=open, close_candle=close, high=high, low=low) count = count + 1 print('Salvo com sucesso! Data/Hora: {}' .format(date.strftime('%d/%m/%Y %H:%M:%S'))) print('Nº de candles salvos: ', count) time.sleep(args.period)
def init_database(): print("INFO: Connecting to the internal database.") # Connecting to the database and creating tables if they do not exist db = object() try: db = Database( os.environ['DB_HOST'], os.environ['DB_USER'], os.environ['DB_PASSWD'], os.environ['DB_NAME'] ) db.create_tables() except mysql.connector.Error as err: system_error(err, "Cannot initialize the database.") return db
from sql import Database, Column, Table db = Database('data.db') users = Table(db, 'users', [ Column('id', 'INTEGER'), Column('score', 'REAL'), Column('prev_msg', 'INTEGER'), Column('tod_msg', 'INTEGER') ]) total_msg = TABLE(db, 'total_msg', [ Column('id', 'INTEGER'), Column('msg', 'INTEGER'), Column('tod_msg', 'INTEGER') ]) def add_user(id_str): users.add_element(id_str, {'score': 50}) def update_user_msg_count(id_str): if users.get(id_str) is None: add_user(id_str) prev_count = users.get(id_str, "tod_msg") users.update(id_str, {"tod_msg": prev_count[0] + 1}) update_server_msg_count() def update_server_msg_count(): if total_msg.get(1) is None:
from flask import Flask, request, jsonify from flask_restful import reqparse from os import getenv import datetime as dt from sql import Database app = Flask(__name__) database = Database() @app.route('/api/account/signup', methods=['POST']) def signUp(): parser = reqparse.RequestParser() parser.add_argument('user', type=str, required=True, help='Parameter not sufficient') parser.add_argument('passwd', type=str, required=True, help='Parameter not sufficient') data = parser.parse_args() test = database.getAccountInfo(data['user']) if test: return jsonify({'status': False}) database.createAccount((data['user'], data['passwd'])) info = database.getAccountInfo(data['user']) res = {'status': True, 'info': {'id': info[0], 'user': info[1]}}
from cogs.games import Card init_time = datetime.datetime.now() RED_CARDS_GUILD_ID = 839985921302069248 BLACK_CARDS_GUILD_ID = 839986047035506708 warnings.filterwarnings("ignore") initial_extensions = [ "cogs.utility", "cogs.economy", "cogs.games", "cogs.radio" ] bot = Bot(command_prefix="$") slash = SlashCommand(bot, sync_commands=True, sync_on_cog_reload=True) bot.db = Database() bot.db.initialize([ """CREATE TABLE IF NOT EXISTS UserData ( id INT NOT NULL PRIMARY KEY, money INT, role_id INT)""" ]) if __name__ == "__main__": for extension in initial_extensions: bot.load_extension(extension) # Messages me on Discord when the bot is ready (faster than checking logs or typing a command) @bot.event async def on_ready():
def index(): db = Database() candles = db.get() return render_template('index.html', candles=candles)