This repository will give you tools to parse and fetch useful informations of your notes in your Obsidian vault.
I like to do some python scripts with my vault, so this repository is the tool I needed in order to parse my Markdown files.
At the moment, I have implemented a basic parsing library.
from src.Parser import Parser
parser = Parser('/path/to/vault')
By default, the parser will ignore .git
and .obsidian
sub-directories.
If you want to specify which directories to ignore, it has to be done at instanciation.
parser = Parser('/path/to/vault', ignoredDirectories=['directory1', '.obsidian', '.git'])
Be careful, it will rewrite .git
and .obsidian
, so please add them back in the ignoredDirectories if you want to ignore them plus the ones you specified.
mdFiles
Array of MarkdownFile in vault
findSubFilesForFiles(files)
returns a set ofMarkdownFile
linked with the set ofMarkdownFile
specifiedsearchFilesWithTag(tag)
returns a set ofMarkdownFile
with a specified tag
from src.yamlParser import YamlParser, YAML_METHOD
# the file contents need to be read
file = MarkdownFile
file = self._openFile()
self.fStream = file.read()
file.close()
findYAMLTags = YamlParser(self.fStream)
# find all values for a particular key
# this will return a set with the values that have "tags" as key
values = findYAMLTags.findAllYAML(YAML_METHOD.FIND_VALUE, "tags")
yamlIterator = YamlParser(self.fStream)
# return all keys and values as a dictionary with the key as string and its values as set
print(yamlIterator.findAllYAML(YAML_METHOD.ITERATE))
.findAllYAML()
with the parametersYAML_METHOD.FIND_VALUE
and"{key}"
with{key}
as the YAML key returns the associated values as a set.findAllYAML()
with the parameterYAML_METHOD.ITERATE
will return all key-value pairs in YAML as a dictionary with the key as a string and its associated values as a set
Currently, the YAML parser is limited (see the comments for details).
fileName
file name (string) of the current markdown file, with.md
extension (e.g'file.md'
)path
relative path (string) of the current markdown file (e.g'testVault/file.md'
)tags
set of tags in current file (e.g{'tag2', 'tag3'}
)links
set of links in markdown files (e.g{'file2'}
)
parser = Parser('test/testVault')
- Find all fileNames that doesn't have a tag
fileWithoutTags = [file.fileName for file in parser.mdFiles if len(file.tags) == 0]
- Find all files that have
tag1
in them
filesWithSpecificTag = [file for file in parser.mdFiles if 'tag1' in file.tags]
# OR
filesWithSpecificTag = parser.searchFilesWithTag('tag1')
New features I intend to add:
- Add more tests
- Ignore .obsidian/ folder
If you would like to add shiny new features, or correct bugs I unfortunately added, please fork this repository, and create a pull request from it. Below is the list of all contributors for this repository, if you contributed please consider adding your name !
Contributors:
- Daniel Mathiot (danymat)