Example #1
import random
import itertools
import string
from flask import Flask, jsonify, redirect, render_template, request, session, url_for

app = Flask(__name__)
# This key is a random string that is used for session cookie management
app.secret_key = "8edca468f5f7bb849e5d8bedb" + str(random.randint(0, 100000))
# Store all games in this map (global variable)
# maps game_id (str) -> Game
app.games = {}
# Store all users in this map
# maps user_id (str) -> User
app.users = {}

    "bootstrap_css": "css/bootstrap.min.css",
    "bootstrap_js": "js/bootstrap.min.js",
    "d3_js": "js/d3.v3.min.js",
    "favicon_ico": "favicon.ico",
    "front_page_js": "js/front_page.js",
    "game_css": "css/game.css",
    "game_page_js": "js/game_page.js",
    "jquery_js": "js/jquery-2.0.3.min.js",
    "lib_js": "js/lib.js",

def get_id():
    """Returns a random 10 character string, which can be used to identify objects."""
    characters = string.ascii_uppercase + string.ascii_lowercase + string.digits
Example #2
from flask import render_template
from flask import redirect
from flask import request
from flask import url_for
from config import *
from casinochain import *
from lottogame import *
from cointossgame import *
import json

app = Flask(__name__)

# Enable Lotto and Coin Toss games
app.NIST_GAMES_AVAILABLE = {"Lotto": LottoGame, "CoinToss": CoinTossGame}
app.latest_game_id = 2
app.games = {0: CasinoChain(), 1: CasinoChain()}
app.curr_game_ids = {"Lotto": 0, "CoinToss": 1}

def get_or_current_id(id, game_type):
    if not game_type in app.curr_game_ids:
        return None
    if id is not None:
        id = int(id)
        if id in app.games:
            return id
        return None
    if app.games[app.curr_game_ids[game_type]].is_active() and not app.games[app.curr_game_ids[game_type]].is_done():
        return app.curr_game_ids[game_type]