from madness import Madness, request, context, json, response from exceptions import APIException app = Madness() @app.context def setup(): context.x = 3101 @app.context def catch(): """ render APIException to JSON """ try: response = yield except APIException as exception: yield json.response({'message': exception.message}, status=exception.status) @app.index def home(x): text = f''' <!DOCTYPE html> <html> <head> </head>
# https://github.com/jpadilla/pyjwt # https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs-html5-web-storage # http://werkzeug.pocoo.org/docs/0.14/contrib/securecookie/ import jwt from functools import partial from madness import Madness, json, response, request, context #from werkzeug.utils import redirect app = Madness() @app.context def jwt_config(): secret = 'my-secret' algorithm = 'HS256' class myjwt: encode = partial(jwt.encode, key=secret, algorithm=algorithm) decode = partial(jwt.decode, key=secret, algorithms=[algorithm]) context.jwt = myjwt() @app.post def login(jwt): # get some data from the json request username, password = json.request('username', 'password')
#!/usr/bin/env python3.7 import sys sys.path.insert(0, '..') from madness import Madness, json from flask import Flask, jsonify app = Madness() @app.index def index(): return json.response({'madness': True}, status=200) flask = Flask(__name__) flask.debug = True @flask.route('/flask') def flask_extra(): response = jsonify(flask=True) response.status_code = 200 return response @flask.errorhandler(404) def flask404(e): return jsonify(flask404=True)
from madness import Madness, response, request, json from exceptions import Forbidden app = Madness() def user(): username = request.headers.get('x-username') if username != None: context.username = username else: raise Forbidden() @app.index def home(x): text = f''' <!DOCTYPE html> <html> <head> </head> <body> <center> <h1>Welcome to Module</h1> <h2>x is {x}</h2> <a href='{request.path}/protected'>protected page</a> <a href='module.json'>module info</a> <hr> <a href='..'>back</a> </center>
from madness import Madness from tqdm import tqdm import pandas as pd if __name__ == "__main__": #Schools schools = Madness.schools() #schools.to_csv("data/schools.csv") #Gamelogs dfs = list() for ind, school in tqdm(schools.iterrows()): df = Madness.gamelog_all_years(school["school_id"]) if isinstance(df, pd.DataFrame): dfs.append(df) df = pd.concat(dfs).to_csv("data/2021gamelogs.csv") ''' #Tournaments dfs = list() for year in range(1995, 2020): df = Madness.tournament(year) if isinstance(df, pd.DataFrame): dfs.append(df) df = pd.concat(dfs).to_csv("data/tournaments.csv") '''
from madness import Madness, json app = Madness() @json.schema class MyEvent(): x: int = 1 @app.lambda_handler def process(event: MyEvent): # curl -v --data '{"x": []}' 127.0.0.1:9090/process # curl --data '{"x": 1}' 127.0.0.1:9090/process print('event is', event) return {'a': 23} if __name__ == '__main__': app.run()
from madness import Madness if __name__ == "__main__": print(Madness.tournament(2019))