def download_daily_aggTrades(trading_type, symbols, num_symbols, dates, start_date, end_date, folder, checksum): current = 0 date_range = None if start_date and end_date: date_range = start_date + " " + end_date if not start_date: start_date = START_DATE else: start_date = convert_to_date_object(start_date) if not end_date: end_date = END_DATE else: end_date = convert_to_date_object(end_date) print("Found {} symbols".format(num_symbols)) for symbol in symbols: print("[{}/{}] - start download daily {} aggTrades ".format(current+1, num_symbols, symbol)) for date in dates: current_date = convert_to_date_object(date) if current_date >= start_date and current_date <= end_date: path = get_path(trading_type, "aggTrades", "daily", symbol) file_name = "{}-aggTrades-{}.zip".format(symbol.upper(), date) download_file(path, file_name, date_range, folder) if checksum == 1: checksum_path = get_path(trading_type, "aggTrades", "daily", symbol) checksum_file_name = "{}-aggTrades-{}.zip.CHECKSUM".format(symbol.upper(), date) download_file(checksum_path, checksum_file_name, date_range, folder) current += 1
def get_problem_content(id): problem = open(get_path(PATH['ASS'] + [get_problem(id)]), 'r', encoding="utf-8") content = problem.read() problem.close() return content
def get_result_content(id): stamp = query_db('SELECT stamp FROM submissions WHERE id=%d' % (id), (), False, True)[0] file = open(get_path(PATH['UPL'] + [stamp]), 'r') result = file.read() file.close() return result
def patch(): l = query_db('SELECT id FROM submissions WHERE process=1') for e in l: submission = {} results = query_db('SELECT * FROM submissions WHERE id = %d' % (e[0]), (), False, True) for (column, result) in zip(SUBMISSION_COLUMN, results): submission[column] = result validation = get_path(PATH['INS'] + [str(submission['problem_id'])]) (ret, res) = scoring(get_path(PATH['UPL'] + [submission['stamp']]), validation) queue_result.put({ 'id': submission['id'], 'process': res == "None" and 2 or 1, 'result': res }) fetch_process()
def read_data_file(): file = utility.get_path(CARDS_FILE) try: with open(file, encoding='utf-8') as f: data = yaml.load(f, Loader=yaml.FullLoader) except FileNotFoundError as e: print(f'Missing or damaged cards.yml configuration file\n({e})') else: return data
def get_problems(args=PROBLEM_ARGS): problems = [] for each in os.listdir(get_path(PATH['ASS'], True)): problem = {} for (arg, value) in zip(PROBLEM_ARGS, each.split('.')): if arg in args: problem[arg] = value problems.append(problem) return problems
def download_monthly_trades(trading_type, symbols, num_symbols, years, months, start_date, end_date, folder, checksum): current = 0 date_range = None if start_date and end_date: date_range = start_date + " " + end_date if not start_date: start_date = START_DATE else: start_date = convert_to_date_object(start_date) if not end_date: end_date = END_DATE else: end_date = convert_to_date_object(end_date) print("Found {} symbols".format(num_symbols)) for symbol in symbols: print("[{}/{}] - start download monthly {} trades ".format( current + 1, num_symbols, symbol)) for year in years: for month in months: current_date = convert_to_date_object('{}-{}-01'.format( year, month)) if current_date >= start_date and current_date <= end_date: path = get_path(trading_type, "trades", "monthly", symbol) file_name = "{}-trades-{}-{}.zip".format( symbol.upper(), year, '{:02d}'.format(month)) download_file(path, file_name, date_range, folder) if checksum == 1: checksum_path = get_path(trading_type, "trades", "monthly", symbol) checksum_file_name = "{}-trades-{}-{}.zip.CHECKSUM".format( symbol.upper(), year, '{:02d}'.format(month)) download_file(checksum_path, checksum_file_name, date_range, folder) current += 1
def run(self): while True: submission = self.submit.get() (ret, res) = scoring(get_path(PATH['UPL'] + [submission['stamp']]), submission['problem_id'], submission['version']) self.submit.task_done() self.result.put({ 'id': submission['id'], 'process': ret, 'result': res })
def download_daily_klines(trading_type, symbols, num_symbols, intervals, dates, start_date, end_date, folder, checksum): current = 0 date_range = None if start_date and end_date: date_range = start_date + " " + end_date if not start_date: start_date = START_DATE else: start_date = convert_to_date_object(start_date) if not end_date: end_date = END_DATE else: end_date = convert_to_date_object(end_date) #Get valid intervals for daily intervals = list(set(intervals) & set(DAILY_INTERVALS)) print("Found {} symbols".format(num_symbols)) for symbol in symbols: print("[{}/{}] - start download daily {} klines ".format(current+1, num_symbols, symbol)) for interval in intervals: for date in dates: current_date = convert_to_date_object(date) if current_date >= start_date and current_date <= end_date: path = get_path(trading_type, "klines", "daily", symbol, interval) file_name = "{}-{}-{}.zip".format(symbol.upper(), interval, date) download_file(path, file_name, date_range, folder) if checksum == 1: checksum_path = get_path(trading_type, "klines", "daily", symbol, interval) checksum_file_name = "{}-{}-{}.zip.CHECKSUM".format(symbol.upper(), interval, date) download_file(checksum_path, checksum_file_name, date_range, folder) current += 1
def get_problem(id): return os.listdir(get_path(PATH['ASS'], True))[id]
def get_submission(filename): result_dic = {} results = query_db( 'SELECT * FROM submissions WHERE stamp = \'%s\'' % (filename), (), False, True) for (column, result) in zip(SUBMISSION_COLUMN, results): result_dic[column] = result return result_dic # for file upload from werkzeug import secure_filename ALLOWED_EXTENSIONS = set(['py']) app.config['UPLOAD_FOLDER'] = get_path(PATH['UPL'], True) def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS # for database import sqlite3 from flask import _app_ctx_stack DATABASE = 'app.db' SCHEMA = 'schema.sql' def init_db():