def get(self): self.db = classes.ScoreDb() self.db.c.execute( "SELECT * FROM scores WHERE saved = ? ORDER BY experience DESC LIMIT 1", (1, )) self.top = self.db.c.fetchone() if not self.top: self.top = [dummy, "", "", "", "", ""] self.db.c.execute( "SELECT * FROM scores WHERE finished = ? AND saved = ? ORDER BY block_start DESC", ( 1, 1, )) self.all_finished = self.db.c.fetchall() if not self.all_finished: self.all_finished = [[dummy, "", "", "", "", ""]] self.db.c.execute( "SELECT * FROM scores WHERE finished = ? AND saved = ? ORDER BY block_start DESC", ( 0, 1, )) self.all_unfinished = self.db.c.fetchall() if not self.all_unfinished: self.all_unfinished = [[dummy, "", "", "", "", ""]] self.render("main.html", title="Autogame", top=self.top, all_finished=self.all_finished, all_unfinished=self.all_unfinished)
def get(self, league): self.db = classes.ScoreDb() self.db.c.execute("SELECT SUM(bet) FROM scores WHERE league = ?", (league, )) self.pot = self.db.c.fetchone()[0] self.db.c.execute( "SELECT * FROM scores WHERE league = ? ORDER BY experience DESC LIMIT 1", (league, )) self.top = self.db.c.fetchone() if not self.top: self.top = [dummy, "", "", "", "", ""] self.db.c.execute( "SELECT * FROM scores WHERE league = ? ORDER BY block_start DESC", (league, )) self.all_finished = self.db.c.fetchall() if not self.all_finished: self.all_finished = [[dummy, "", "", "", "", ""]] self.db.c.execute( "SELECT * FROM unfinished WHERE league = ? ORDER BY block_start DESC", (league, )) self.all_unfinished = self.db.c.fetchall() if not self.all_unfinished: self.all_unfinished = [[dummy, "", "", "", "", ""]] self.render("tournament.html", title=f"{league}", top=self.top, all_finished=self.all_finished, all_unfinished=self.all_unfinished, pot=self.pot)
def get(self, league): self.db = classes.ScoreDb() #collect pot self.db.c.execute( "SELECT SUM(bet) FROM scores WHERE league = ? AND finished = ?", ( league, 1, )) self.pot_finished = self.db.c.fetchone()[0] self.pot_finished = 0 if self.pot_finished is None else self.pot_finished self.db.c.execute( "SELECT SUM(bet) FROM scores WHERE league = ? AND finished = ?", ( league, 0, )) self.pot_unfinished = self.db.c.fetchone()[0] self.pot_unfinished = 0 if self.pot_unfinished is None else self.pot_unfinished self.pot = self.pot_unfinished + self.pot_finished # collect pot self.db.c.execute( "SELECT * FROM scores WHERE league = ? AND saved = ? ORDER BY experience DESC LIMIT 1", (league, 1)) self.top = self.db.c.fetchone() if not self.top: self.top = [dummy, "", "", "", "", ""] self.db.c.execute( "SELECT * FROM scores WHERE league = ? AND finished = ? AND saved = ? ORDER BY block_start DESC", ( league, 1, 1, )) self.all_finished = self.db.c.fetchall() if not self.all_finished: self.all_finished = [[dummy, "", "", "", "", ""]] self.db.c.execute( "SELECT * FROM scores WHERE league = ? AND finished = ? and saved = ? ORDER BY block_start DESC", ( league, 0, 1, )) self.all_unfinished = self.db.c.fetchall() if not self.all_unfinished: self.all_unfinished = [[dummy, "", "", "", "", ""]] self.render("tournament.html", title=f"{league}", top=self.top, all_finished=self.all_finished, all_unfinished=self.all_unfinished, pot=self.pot)
def get(self, seed): self.db = classes.ScoreDb() self.db.c.execute("SELECT hash FROM scores WHERE seed = ?", (seed, )) self.db_seed_matches = [h[0] for h in self.db.c.fetchall()] self.write(json.dumps(self.db_seed_matches)) self.set_header('Content-Type', 'application/json' ) # send the matching header for paranoid clients self.finish()
def get(self, hash): self.db = classes.ScoreDb() self.db.c.execute("SELECT * FROM scores WHERE hash = ?", (hash, )) self.db_hashes = self.db.c.fetchall()[0] print(self.db_hashes) api_dict = {} api_dict["block_start"] = self.db_hashes[0] api_dict["hash"] = self.db_hashes[1] api_dict["seed"] = self.db_hashes[2] api_dict["experience"] = self.db_hashes[3] try: # Not sure the try is needed, to be checked. # decode inventory, stored as a single json-encoded in the db api_dict["inventory"] = json.loads(self.db_hashes[4]) except: pass api_dict["league"] = self.db_hashes[5] api_dict["bet"] = self.db_hashes[6] try: # Not sure the try is needed, to be checked. api_dict["damage"] = json.loads(self.db_hashes[7]) except: pass try: # Not sure the try is needed, to be checked. api_dict["defense"] = json.loads(self.db_hashes[8]) except: pass api_dict["block_end"] = self.db_hashes[9] api_dict["finished"] = self.db_hashes[10] print(api_dict) self.write(json.dumps(api_dict)) self.set_header('Content-Type', 'application/json' ) # send the matching header for paranoid clients self.finish()
import time import classes import sqlite3 import os import json from hashlib import blake2b coordinator = "fefb575972cd8fdb086e2300b51f727bb0cbfc33282f1542e19a8f1d" league_requirement = 5 config = classes.Config() db = classes.Db(config.path["ledger"]) scores_db = classes.ScoreDb() def go(match): game = classes.Game() game.properties = { "seed": match[2], "block": match[0], "recipient": match[3], "amount": match[4], "league": match[11] } game.start_block = game.properties["block"] game.recipient = game.properties["recipient"] game.bet = game.properties["amount"] game.current_block = game.start_block game.seed = game.properties["seed"]