{ 'type': 'number', 'format': 'float' }
      ]
    }
  }
})

@app.route('/')
class Root(Resource):
  async def get(self):
    '''Note Route

    This docstring will show up as the description and short-description
    for the openapi docs for this route.
    '''
    return jsonify({"Note": "There exists a localhost:9000/openapi.json that can be helpful here"})
  @app.expect(expected)
  async def post(self): 
    '''Post Hello Route

    Data should be sent through postman (but postman does not have HTTP/2, for that you need `curl --http2`) with HTTPS POST "1": { "foobar": "super", "baz": 5.56 }
    '''
    data = await request.get_json()
    return jsonify(data)


if __name__ == "__main__":
    app.run(host='localhost', 
        port=8080, 
        certfile='cert.pem', 
        keyfile='key.pem')
Пример #2
0
@app.route("/what_if", methods=["POST"])
class WhatIf(Resource):
    async def post(self):
        return "Calculating"


@app.route("/result", methods=["POST"])
class Result(Resource):
    async def post(self):
        return "result"


@app.errorhandler(Exception)
async def handle_exception(e):
    if isinstance(e, HTTPException):
        response = e.get_response()
        response.data = json.dumps({
            "code": e.code,
            "name": e.name,
            "description": e.description,
        })
        response.content_type = "application/json"
        app.logger.error("HTTP Error 500")
        return response
    app.logger.error(e)
    return await render_template("500_generic.html", e=e)


if __name__ == "__main__":
    app.run()
Пример #3
0
            return '',204
            
        session.permanent = True
        app.permanent_session_lifetime = datetime.timedelta(hours=1)

        # session.permanent = False

        # return '', 200
    except:
        traceback.print_exc()
        return '', 401

@app.route('/session', methods=['GET'])
async def Session():
    print('session',session)
    return '',200


from Routes.Department import *
from Routes.Tasks import * 
from Routes.Auth import *
from Routes.TaskHistory import * 
from Routes.Employee import * 


if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000, debug=True)
    #app.run(host='0.0.0.0', port=80)


Пример #4
0
app = Pint(__name__)

# Register Blueprints
app.register_blueprint(user)
app.register_blueprint(user_confirm)


load_dotenv('.env', verbose=True)
app.config.from_object('default_config')
app.config.from_envvar('APPLICATION_SETTINGS')
jwt = JWTManager(app)


@app.before_first_request
async def create_tables():
    async with app.app_context():
        db.create_all()


@jwt.token_in_blacklist_loader
def check_if_token_in_blacklist(decrypted_token):
    jti = decrypted_token['jti']
    return TokenBlacklist.is_jti_blacklisted(jti)


if __name__ == "__main__":
    psw.init_app(app)
    db.init_app(app)
    asyncio.create_task(app.run())
Пример #5
0
        exc = sys.exc_info()[1]
        if exc:
            exc.argument = self._get_action_from_name(exc.argument_name)
            raise exc
        # super(SrlArgumentParser, self).error(message)

# small restful API server running locally so my other bots can send messages

app = Pint(__name__, title='Srl Bot API')

@app.route('/api/message')
class Message(Resource):
    async def post(self):
        data = await request.get_json()
        if 'auth' in data and data['auth'] == c.InternalApiToken:
            if not client.in_channel(data['channel']):
                abort(400, "Bot not in specified channel")
            result = await client.message(data['channel'], data['message'])
            return jsonify({"success": True})
        else:
            abort(401)

if __name__ == '__main__':
    client = SrlBot(c.SRL_NICK, realname=c.SRL_NICK)
    loop = asyncio.get_event_loop()
    loop.create_task(orm.create_pool(loop))

    loop.create_task(client.connect('irc.speedrunslive.com'))
    loop.create_task(app.run(host='127.0.0.1', port=5000, loop=loop))
    loop.run_forever()
Пример #6
0
a root ("/") endpoint.
Replies Hello! to all valid requests. Rejects all rate exceeding requests with
429 statius code.
"""
import os
from quart import Quart, redirect, url_for
from quart_openapi import Pint, Resource
from decorators.rate_limit import rate_limit

REQUEST_COUNT = os.getenv("REQUEST_COUNT", "1")
INTERVAL = os.getenv("INTERVAL", "5")

PROXY = Pint(__name__, title="Rate Limiting Proxy App")


@PROXY.route("/")
class RateLimitProxyRoot(Resource):
    """This route is used to limit the rate of the incoming requests to a
    configured REQUEST_COUNT per INTERVAL. The configuration is read from
    the environment.
    """
    @rate_limit(int(REQUEST_COUNT), int(INTERVAL))
    async def get(self):
        """Get request.
        """
        return "Hello!"


if __name__ == "__main__":
    PROXY.run(port=7070)
Пример #7
0
        resp = await client.send_file('me', file.filename)

        print(resp)

        os.remove(file.filename)

        return 'Done'


# async def main():
#     await hypercorn.asyncio.serve(app, hypercorn.Config())

# By default, `Quart.run` uses `asyncio.run()`, which creates a new asyncio
# event loop. If we create the `TelegramClient` before, `telethon` will
# use `asyncio.get_event_loop()`, which is the implicit loop in the main
# thread. These two loops are different, and it won't work.
#
# So, we have to manually pass the same `loop` to both applications to
# make 100% sure it works and to avoid headaches.
#
# To run Quart inside `async def`, we must use `hypercorn.asyncio.serve()`
# directly.
#
# This example creates a global client outside of Quart handlers.
# If you create the client inside the handlers (common case), you
# won't have to worry about any of this, but it's still good to be
# explicit about the event loop.
if __name__ == '__main__':
    app.run('localhost', port=5000, debug=True)