Skip to content

Text file

TextFileConf

Bases: BaseModel

Text File config model.

Parameters:

Name Type Description Default
filepath str

Path to text file.

required
Source code in stac_generator/plugins/outputs/text_file.py
14
15
16
17
18
19
class TextFileConf(BaseModel):
    """Text File config model."""

    filepath: str = Field(
        description="Path to text file.",
    )

TextFileOutput

Bases: Output

Outputs to a text file.

Plugin name: file_out

Example Configuration

.. code-block:: yaml

- name: file_out
  conf:
    filepath: location_to_destination_file
Source code in stac_generator/plugins/outputs/text_file.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class TextFileOutput(Output):
    """
    Outputs to a text file.

    **Plugin name:** ``file_out``

    Example Configuration:
        .. code-block:: yaml

            - name: file_out
              conf:
                filepath: location_to_destination_file
    """

    config_class = TextFileConf

    def export(self, data: dict, **kwargs) -> None:

        if os.path.isdir(self.conf.filepath):
            self.conf.filepath = os.path.join(self.conf.filepath, "file_out.txt")

        with open(self.conf.filepat, "a", encoding="utf-8") as file:
            file.write(f"{data}\n")