1
0
mirror of synced 2024-12-01 00:57:18 +01:00
bemaniutils/bemani/utils/api.py
2019-12-08 21:43:49 +00:00

35 lines
1.1 KiB
Python

import argparse
import yaml # type: ignore
from bemani.data import Data
from bemani.api import app, config # noqa: F401
def load_config(filename: str) -> None:
global config
config.update(yaml.safe_load(open(filename))) # type: ignore
config['database']['engine'] = Data.create_engine(config)
def main() -> None:
parser = argparse.ArgumentParser(description="An API services provider for eAmusement games, conforming to BEMAPI specs.")
parser.add_argument("-p", "--port", help="Port to listen on. Defaults to 80", type=int, default=80)
parser.add_argument("-c", "--config", help="Core configuration. Defaults to server.yaml", type=str, default="server.yaml")
parser.add_argument("-r", "--profile", help="Turn on profiling for API", action="store_true")
args = parser.parse_args()
# Set up app
load_config(args.config)
if args.profile:
from werkzeug.contrib.profiler import ProfilerMiddleware # type: ignore
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, profile_dir='.') # type: ignore
# Run the app
app.run(host='0.0.0.0', port=args.port, debug=True)
if __name__ == '__main__':
main()