62 lines
1.7 KiB
Markdown
62 lines
1.7 KiB
Markdown
# 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`.
|
|
It is recommended to put the `omg.py` into `~/bin/` and to make it executable with `chmod +x ~/bin/omg.py`.
|
|
If you did that, you can now delete every other file that came with OMG. The script is now executable from everywhere.
|
|
|
|
Example usage:
|
|
|
|
```shell
|
|
cd ~/.obsidian/myVault
|
|
omg.py .
|
|
```
|
|
|
|
### 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()
|
|
```
|