@app.get("/entity/remove/{category_id}") async def add_category(category_id, category_name): key = TRACKING_CATEGORIES_KEY categories = redis_get_json(key) updated_categories = [x for x in categories if x[0] != category_id] return redis_put_as_json(key, updated_categories) @app.get("/categories") async def show_all_spotify_categories(): tracker = RedisPlaylistTracker( redis_credentials=settings.redis_credentials) return tracker.get_categories() if __name__ == '__main__' and not os.environ.get('DOCKER', None): from hypercorn.config import Config config = Config() config.bind = ["localhost:8000"] # As an example configuration setting config.debug = True import asyncio from hypercorn.asyncio import serve asyncio.run(serve(app, Config()))
from bareasgi import Application, text_reader, text_writer import bareutils.header as header async def get_info(scope, info, matches, content): accept = header.find(b'accept', scope['headers']) if accept != b'application/json': return 500 text = json.dumps(info) headers = [(b'content-type', b'application/json')] return 200, headers, text_writer(text) async def set_info(scope, info, matches, content): content_type = header.find(b'content-type', scope['headers']) if content_type != b'application/json': return 500 text = await text_reader(content) data = json.loads(text) info.update(data) return 204 app = Application(info={'name': 'Michael Caine'}) app.http_router.add({'GET'}, '/info', get_info) app.http_router.add({'POST'}, '/info', set_info) config = Config() config.bind = ["0.0.0.0:9009"] asyncio.run(serve(app, config))
abort(404) study = app.study # type: ignore matching_users = await study.username_lookup(match) return jsonify(matching_users) def _exception_handler(loop: asyncio.AbstractEventLoop, context: dict) -> None: exception = context.get("exception") if isinstance(exception, ssl.SSLError): pass # Handshake failure else: loop.default_exception_handler(context) # doesn't get run with hypercorn if __name__ == "__main__": if os.getenv("MODE") == "production": config = Config() config.certfile = os.getenv("CERTFILE") config.keyfile = os.getenv("KEYFILE") config.bind = [os.getenv("BIND")] loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop.set_debug(debug_mode) loop.set_exception_handler(_exception_handler) loop.run_until_complete(serve(app, config)) else: app.run(host="0.0.0.0", debug=debug_mode)
app.http_router.add({'GET'}, '/', index) app.http_router.add({'GET'}, '/test', test_page) app.http_router.add({'POST', 'OPTION'}, '/events', test_events) from hypercorn.asyncio import serve from hypercorn.config import Config loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) shutdown_event = asyncio.Event() def _signal_handler(*_: Any) -> None: shutdown_event.set() loop.add_signal_handler(signal.SIGTERM, _signal_handler) loop.add_signal_handler(signal.SIGINT, _signal_handler) config = Config() config.bind = ["0.0.0.0:9009"] config.loglevel = 'debug' # config.certfile = os.path.expanduser(f"~/.keys/server.crt") # config.keyfile = os.path.expanduser(f"~/.keys/server.key") loop.run_until_complete( serve( app, config, shutdown_trigger=shutdown_event.wait # type: ignore ))