Use mode
You can use Monkey Wrench in two modes:
As a Python package that can be easily imported and used in Python codes/scripts.
As a standalone executable, essentially serving as a task manager which reads and runs tasks from YAML files.
For examples on how to use Monkey Wrench, refer to examples. Therein you can find several example sub-directories.
In each sub-directory, there are two files, namely script.py and task.yaml. The former demonstrates how
Monkey Wrench can be used as a Python package, and the latter shows how you can use Monkey Wrench as a task runner.
Note that the two modes are equivalent and the results are identical. As a result, depending on your use case, you can choose a use mode that you deem fit.
Package mode
As an example, to obtain all product IDs for SEVIRI native data between 2022/01/01 (inclusive) and 2024/01/01
(exclusive) and save them in seviri_product_ids.txt, you can do the following in a Python script:
from datetime import UTC, datetime, timedelta
from pathlib import Path
from monkey_wrench.date_time import DateTimeRangeInBatches
from monkey_wrench.input_output import Writer
from monkey_wrench.query import EumetsatQuery
output_filepath = Path("<replace_with_the_full_path_of_the_text_file_in_which_product_ids_are_to_be_stored>")
writer = Writer(output_filepath=output_filepath)
datetime_range_in_batches = DateTimeRangeInBatches(
start_datetime=datetime(2022, 1, 1, tzinfo=UTC),
end_datetime=datetime(2024, 1, 1, tzinfo=UTC),
batch_interval=timedelta(days=30)
)
if __name__ == "__main__":
product_batches = EumetsatQuery().query_in_batches(datetime_range_in_batches)
number_of_items = writer.write_in_batches(product_batches)
print("number of items successfully fetched and written to the file: ", number_of_items)
The above example is available in script.py.
Task runner mode
You can achieve the same results as the Package mode by using the task runner instead. Create a new YAML file
with the following content and an arbitrary valid filename, e.g., task.yaml:
context: ids
action: fetch
specifications:
start_datetime: "2022-01-01T00:00:00+00:00"
end_datetime: "2024-01-01T00:00:00+00:00"
batch_interval:
days: 30
output_filepath: <replace_with_the_full_path_of_the_text_file_in_which_product_ids_are_to_be_stored>
Then run the task via:
monkey-wrench task.yaml
The above example is available in task.yaml. The results are identical to those of the Package mode example.