Added README.md and command line interface.
This commit is contained in:
parent
b3a40035cd
commit
41719a6888
2 changed files with 63 additions and 2 deletions
53
README.md
Normal file
53
README.md
Normal file
|
@ -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()
|
||||||
|
```
|
12
omg.py
12
omg.py
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
import json
|
import json
|
||||||
import collections.abc
|
import collections.abc
|
||||||
|
@ -232,6 +233,13 @@ def recursive_update(a: collections.abc.Mapping, b: collections.abc.Mapping) ->
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue