parsers package

parsers module

mindreader.parsers.parsers.get_available_parsers() → list

Returns the list of available parsers.

mindreader.parsers.parsers.load_parsers()

Loads dynamically all the available parsers. In order to add a new parser, check the ‘parsers’ section in the README.md of this package.

mindreader.parsers.parsers.parse(parser_name: str, raw_snapshot: str) → str

Runs a parser on a snapshot.

Parameters
  • parser_name – name of the parser to use.

  • raw_snapshot – a snapshot, in raw (JSON) format.

Raises

NotImplementedError – the parser does not exist.

Returns

the result of the parsing, in JSON format.

mindreader.parsers.parsers.run_all_parsers(mq_url)

Receives a url to a message queue, and runs all parsers available, each in a different thread (using run_parser).

mindreader.parsers.parsers.run_parser(parser_name: str, mq_url: str, debug: bool = False)

Runs a parser as a service, so it registers to a message queue, parse snapshots received on a queue, and pass the results back to another queue.

Parameters
  • parser_name – name of the parser to use.

  • mq_url – a url to the queue. The prefix should indicate the type of the message queue (for example: rabbitmq://…)

  • debug – if enabled, the parsing results will be printed before passing them to the queue

mindreader.parsers.parsers.wrap_parser_result(data: dict, data_type: str, snapshot: mindreader.objects.snapshot.Snapshot) → dict

Wraps data produced by a parser, with metadata needed for the next stages.

Parameters
  • data – The data, produced by some parser.

  • data_type – The type of the data (usually the name of the parser that produced it).

  • snapshot – A snapshot object.

Returns

The wrapped object.

CLI

python -m mindreader.parsers

python -m mindreader.parsers [OPTIONS] COMMAND [ARGS]...

parse

python -m mindreader.parsers parse [OPTIONS] PARSER_NAME PATH

Arguments

PARSER_NAME

Required argument

PATH

Required argument

run-parser

python -m mindreader.parsers run-parser [OPTIONS] PARSER_NAME MQ_URL

Options

--debug, --no-debug

If enabled, the parsing results will be printed

Arguments

PARSER_NAME

Required argument

MQ_URL

Required argument

run-parsers

python -m mindreader.parsers run-parsers [OPTIONS] MQ_URL

Arguments

MQ_URL

Required argument