diff --git a/README.md b/README.md new file mode 100644 index 0000000..ff2bec6 --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# OMG +_OMG - Obsidian Metadata Generator_ + +OMG is a simple python script that generates metadata like the "Metadata Extractor"-plugin does. +It cannot do as much as the plugin because it was made to generate metadata for +[Perlite](https://github.com/secure-77/Perlite). + +## Setup +Before you can use the script, you have to install the dependencies. +Normally, you would install the dependencies like this: + +```shell +pip install -r requirements.txt +``` + +(which also works on this project) + +But since OMG has only one dependency, (pyyaml) you can simply run + +```shell +pip install pyyaml +``` + +## Usage + +### Command Line +The script is usable from the command line. It takes 2 arguments: `vault_path` and `metadata_path`. +`metadata_path` comes after `vault_path` and is optional because it has a default value of `vault_path/metadata.json`. + +### Python API +To use the script as a module, simply import it and create an instance of the OMG class with the `path`-parameter set +to your vault path. The metadata is stored as a dict in `instance.md_files`. + +Example: + +```python +from omg import OMG + +metadata = OMG("/home/user/.obsidian/myVault") +as_dict = metadata.md_files +``` + +To write the metadata, you can use `instance.dump(path: Pathlike=None, indent=2)`. +This will create a `metadata.json` in your vault by default, but you can also specify any other path. + +Example: + +```python +from omg import OMG + +metadata = OMG("/home/user/.obsidian/myVault") +metadata.dump() +``` diff --git a/omg.py b/omg.py index 9e93970..f797fd1 100644 --- a/omg.py +++ b/omg.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import os +import sys import yaml import json import collections.abc @@ -232,6 +233,13 @@ def recursive_update(a: collections.abc.Mapping, b: collections.abc.Mapping) -> if __name__ == "__main__": - bla = OMG("/home/emil/Dokumente/Obsidian/Gulm") + if len(sys.argv) > 1: + vault_path = sys.argv[1] + metadata_path = None + + if len(sys.argv) > 2: + metadata_path = sys.argv[2] + + metadata = OMG(vault_path) + metadata.dump(metadata_path) - print(json.dumps(bla.md_files, indent=2))