def web_hook():
    if request.method == 'POST':
        if request.headers.get('content-type') == 'application/json':
            json_string = request.get_data().decode('utf-8')
            update = telebot.types.Update.de_json(json_string)
            bot.process_new_updates([update])
            return ''
        else:
            request.abort(403)
    return ''
Exemplo n.º 2
0
    def batch_metadata():
        """
            Returns endpoint metadata in batch format
            """
        server.show_metadata = True

        if request.method == 'GET':
            """this will return sensible defaults in the future"""
            return server.app.make_response(json.dumps(metric_metadata))

        try:
            requests = json.loads(request.data.decode('utf-8'))
        except ValueError as e:
            request.abort(400)

        responses = []

        for index, req in enumerate(requests):
            method = req['method']
            path = req['path']
            body = req.get('body', None)

            try:
                logger.info('batch endpoint: ' + path)
                with server.app.server.app.context():
                    with server.app.test_request_context(path,
                                                         method=method,
                                                         data=body):
                        try:
                            rv = server.app.preprocess_request()
                            if rv is None:
                                rv = server.app.dispatch_request()
                        except Exception as e:
                            rv = server.app.handle_user_exception(e)
                        response = server.app.make_response(rv)
                        response = server.app.process_response(response)

                responses.append({
                    "path": path,
                    "status": response.status_code,
                    "response": str(response.get_data(), 'utf8'),
                })

            except Exception as e:
                responses.append({
                    "path": path,
                    "status": 500,
                    "response": str(e)
                })

        server.show_metadata = False

        return Response(response=json.dumps(responses),
                        status=207,
                        mimetype="server.app.ication/json")
Exemplo n.º 3
0
        def batch():
            """
            Execute multiple requests, submitted as a batch.

            :statuscode 207: Multi status
            """
            if request.method == 'GET':
                """this will return sensible defaults in the future"""
                return app.make_response(
                    '{"status": "501", "response": "Defaults for batch requests not implemented. Please POST a JSON array of requests to this endpoint for now."}'
                )

            try:
                requests = json.loads(request.data)
            except ValueError as e:
                request.abort(400)

            responses = []

            for index, req in enumerate(requests):

                method = req['method']
                path = req['path']
                body = req.get('body', None)

                try:

                    with app.app_context():
                        with app.test_request_context(path,
                                                      method=method,
                                                      data=body):
                            try:
                                # Can modify flask.g here without affecting
                                # flask.g of the root request for the batch

                                # Pre process Request
                                rv = app.preprocess_request()

                                if rv is None:
                                    # Main Dispatch
                                    rv = app.dispatch_request()

                            except Exception as e:
                                rv = app.handle_user_exception(e)

                            response = app.make_response(rv)

                            # Post process Request
                            response = app.process_response(response)

                    # Response is a Flask response object.
                    # _read_response(response) reads response.response
                    # and returns a string. If your endpoints return JSON object,
                    # this string would be the response as a JSON string.
                    responses.append({
                        "path":
                        path,
                        "status":
                        response.status_code,
                        "response":
                        str(response.get_data(), 'utf8')
                    })

                except Exception as e:

                    responses.append({
                        "path": path,
                        "status": 500,
                        "response": str(e)
                    })

            return Response(response=json.dumps(responses),
                            status=207,
                            mimetype="application/json")
        def batch_metadata():
            """
            Returns endpoint metadata in batch format
            """

            self.show_metadata = True

            if request.method == 'GET':
                """this will return sensible defaults in the future"""
                return app.make_response(json.dumps(metric_metadata))

            try:
                requests = json.loads(request.data.decode('utf-8'))
            except ValueError as e:
                request.abort(400)

            responses = []

            for index, req in enumerate(requests):

                method = req['method']
                path = req['path']
                body = req.get('body', None)

                try:

                    augur.logger.info('batch endpoint: ' + path)

                    with app.app_context():
                        with app.test_request_context(path,
                                                      method=method,
                                                      data=body):
                            try:
                                # Can modify flask.g here without affecting
                                # flask.g of the root request for the batch

                                # Pre process Request
                                rv = app.preprocess_request()

                                if rv is None:
                                    # Main Dispatch
                                    rv = app.dispatch_request()

                            except Exception as e:
                                rv = app.handle_user_exception(e)

                            response = app.make_response(rv)

                            # Post process Request
                            response = app.process_response(response)

                    # Response is a Flask response object.
                    # _read_response(response) reads response.response
                    # and returns a string. If your endpoints return JSON object,
                    # this string would be the response as a JSON string.

                    responses.append({
                        "path":
                        path,
                        "status":
                        response.status_code,
                        "response":
                        str(response.get_data(), 'utf8'),
                    })

                except Exception as e:

                    responses.append({
                        "path": path,
                        "status": 500,
                        "response": str(e)
                    })

            self.show_metadata = False

            return Response(response=json.dumps(responses),
                            status=207,
                            mimetype="application/json")
        def batch():
            """
            Execute multiple requests, submitted as a batch.
            :statuscode 207: Multi status
            """
            """
            to have on future batch request for each individual chart:
            - timeseries/metric
            - props that are in current card files (title)
            - do any of these things act like the vuex states?
            - what would singular card(dashboard) look like now?
            """

            self.show_metadata = False

            if request.method == 'GET':
                """this will return sensible defaults in the future"""
                return app.make_response(
                    '{"status": "501", "response": "Defaults for batch requests not implemented. Please POST a JSON array of requests to this endpoint for now."}'
                )

            try:
                requests = json.loads(request.data.decode('utf-8'))
            except ValueError as e:
                request.abort(400)

            responses = []

            for index, req in enumerate(requests):

                method = req['method']
                path = req['path']
                body = req.get('body', None)

                try:

                    logger.debug('batch-internal-loop: %s %s' % (method, path))

                    with app.app_context():
                        with app.test_request_context(path,
                                                      method=method,
                                                      data=body):
                            try:
                                # Can modify flask.g here without affecting
                                # flask.g of the root request for the batch

                                # Pre process Request
                                rv = app.preprocess_request()

                                if rv is None:
                                    # Main Dispatch
                                    rv = app.dispatch_request()

                            except Exception as e:
                                rv = app.handle_user_exception(e)

                            response = app.make_response(rv)

                            # Post process Request
                            response = app.process_response(response)

                    # Response is a Flask response object.
                    # _read_response(response) reads response.response
                    # and returns a string. If your endpoints return JSON object,
                    # this string would be the response as a JSON string.
                    responses.append({
                        "path":
                        path,
                        "status":
                        response.status_code,
                        "response":
                        str(response.get_data(), 'utf8'),
                    })

                except Exception as e:

                    responses.append({
                        "path": path,
                        "status": 500,
                        "response": str(e)
                    })

            return Response(response=json.dumps(responses),
                            status=207,
                            mimetype="application/json")