예제 #1
0
def main():
    src = SourceSampleOrion()
    # if you have an Orion server available, just replace SinkStdout() with SinkOrion()
    sink = SinkStdout()
    agent = NgsiAgent.create_agent(src, sink, process=build_entity)
    agent.run()
    agent.close()
def main():
    src = SourceMqtt(topic="sensor/temperature")
    # if you have an Orion server available, just replace SinkStdout() with SinkOrion()
    sink = SinkStdout()
    agent = NgsiAgent.create_agent(src, sink, process=build_entity)
    agent.run()
    agent.close()
def main():
    response = retrieve_latest_commits(ncommits=3)
    src = SourceJson(response, provider="github")

    # if you have an Orion server available, just replace SinkStdout() with SinkOrion()
    sink = SinkStdout()
    agent = NgsiAgent.create_agent(src, sink, process=build_entity)
    agent.run()
    agent.close()
예제 #4
0
파일: agent.py 프로젝트: pjhaest/pyngsi
 def __init__(self,
              source: Source = None,
              sink: Sink = None,
              process: Callable = lambda row, *args, **kwargs: row.record,
              side_effect: Callable = None):
     logger.info("init NGSI agent")
     self.source = source if source else SourceStream(sys.stdin)
     logger.info(f"source = [{self.source.__class__.__name__}]")
     self.sink = sink if sink else SinkStdout()
     logger.info(f"sink = [{self.sink.__class__.__name__}]")
     self.process = process
     self.side_effect = side_effect
     self.stats = NgsiAgent.Stats()
예제 #5
0
def main():
    src = SourceJson(json_obj)

    # in this example data are embedded in the source
    # you can get json data from any file or stream
    # example : Source.from_file("/tmp/test.json")
    # have a look at the factory methods available in the Source class

    # if you have an Orion server available, just replace SinkStdout() with SinkOrion()
    sink = SinkStdout()
    agent = NgsiAgent.create_agent(src, sink, process=build_entity)
    agent.run()
    agent.close()
예제 #6
0
def main():
    # Get two RFC descriptions (RFC959 and RFC2228) in JSON format
    # For the sake of simplicity the example use a lambda and a basic string function for the match function
    # f_match could be a real function (not just a lambda) and could make use of regular expression
    # By default user/passwd is set to anonymous/guest
    src = SourceFtp("ftp.ps.pl", paths=[
        "/pub/rfc"], f_match=lambda x: x.endswith("rfc958.json") or x.endswith("rfc2228.json"))

    # If you have an Orion server available, just replace SinkStdout() with SinkOrion()
    sink = SinkStdout()

    # The source has auto-detected that we deal with JSON files, hence has parsed json for you
    agent = NgsiAgent.create_agent(src, sink, process=build_entity).run()

    # Resources are freed. Here the agent removes the temporary directory (where files were downloaded).
    agent.close()
예제 #7
0
파일: agent.py 프로젝트: pjhaest/pyngsi
 def __init__(self,
              server: pyngsi.sources.server.Server = None,
              sink: Sink = None,
              process: Callable = lambda row, *args, **kwargs: row.record,
              side_effect: Callable[[Row, Sink, DataModel], int] = None):
     logger.info("init NGSI agent")
     self.server = server
     logger.info(f"server = [{self.server.__class__.__name__}]")
     self.sink = sink if sink else SinkStdout()
     logger.info(f"sink = [{self.sink.__class__.__name__}]")
     self.process = process
     logger.info(f"process = [{self.process}]")
     self.side_effect = side_effect
     logger.info(f"side_effect = [{self.side_effect}]")
     self.server_status = self.ServerStatus()
     self.stats = NgsiAgent.Stats()
예제 #8
0
파일: agent.py 프로젝트: pjhaest/pyngsi
    def create_agent(src: Union[Source, Server] = SourceStream(sys.stdin),
                     sink: Sink = SinkStdout(),
                     process: Callable = lambda x: x.record,
                     side_effect: Callable[[Row, Sink, DataModel],
                                           int] = None):
        """
        Factory method to create the agent depending on the source push/pull.

        :param src: the Source
        :param sink: the Sink
        :param process: a function that takes an input row from the source and outputs a NGSI datamodel
        """
        if isinstance(src, Source):
            return NgsiAgentPull(src, sink, process, side_effect)
        elif isinstance(src, Server):
            return NgsiAgentServer(src, sink, process, side_effect)
        else:
            raise NgsiException(
                f"Cannot create agent. Unknown source type {type(src)}")
예제 #9
0
def main():

    # just provide SourceApi with your own function (that returns an array)

    # default is to retrieve 5 commits
    # override the default provider "api" with "github"
    src = SourceFunc(retrieve_latest_commits, "github")

    # in case you want to retrieve 3 commits, you could use lambda
    # src = SourceFunc(lambda: retrieve_latest_commits(ncommits=3), "github")

    # one could prefer to use the partial function from functools
    # src = SourceFunc(partial(retrieve_latest_commits, ncommits=3), "github")

    # if you have an Orion server available, just replace SinkStdout() with SinkOrion()
    sink = SinkStdout()
    agent = NgsiAgent.create_agent(src, sink, process=build_entity)
    agent.run()
    agent.close()
예제 #10
0
def main():

    # You declare an HTTP server that acts as your Source, listening on port 8880
    src = ServerHttpUpload()

    # If you have an Orion server available, just replace SinkStdout() with SinkOrion()
    sink = SinkStdout()

    # The agent processes CSV content received from the client
    agent = NgsiAgent.create_agent(src, sink, process=build_entity)

    # You must push data to the source, here we send POST requests to the server
    # For example, in a bash shell, send binary content
    # curl --noproxy '*' -v  -H "Content-Type: text/plain" -d $'Room1;23.0;720\nRoom2;21.0;711' "127.0.0.1:8880/upload"
    # You can also send a file, the NGSI datasource provider is set as the filename
    # curl -v -F [email protected] http://127.0.0.1:8880/upload
    # CTRL-C to stop the server
    agent.run()

    # The agent provides global statistics on its execution
    agent.close()
def main():

    # You declare an HTTP server that acts as your Source, listening on port 8880
    src = ServerHttpUpload()

    # If you have an Orion server available, just replace SinkStdout() with SinkOrion()
    sink = SinkStdout()

    # The agent processes JSON content received from the client
    agent = NgsiAgent.create_agent(src, sink, process=build_entity)

    # You must push data to the source, here we send POST requests to the server
    # For example, in a bash shell, type in :
    # curl -X POST -H "Content-Type: application/json" -d '{"room":"Room1","temperature":23.0,"pressure":710}' http://127.0.0.1:8880/upload
    # You could also send a JSON Array. For example, type in :
    # curl -X POST -H "Content-Type: application/json" -d '[{"room":"Room1","temperature":23.0,"pressure":710},{"room":"Room2","temperature":21.0,"pressure":711}]' http://127.0.0.1:8880/upload
    # You can also send a file, the NGSI datasource provider is set as the filename
    # curl -v -F [email protected] http://127.0.0.1:8880/upload
    # CTRL-C to stop the server
    agent.run()

    # The agent provides global statistics on its execution
    agent.close()
예제 #12
0
def test_sink_stdout(capsys):
    sink = SinkStdout()
    sink.write(msg="dummy")
    captured = capsys.readouterr()
    assert captured.out == f"dummy{os.linesep}"