<commit_before>#! /usr/local/bin/python3

import json

def main():
    ''' Creates a list of all the links that Obsidian
    knows about that do not have corresponding files
    yet.

    Written for personal use with no error checking.
    Obsidian's electron anyway, so if it ever opens
    up the chance of writing a plugin to do this
    it'll need done in Javascript rather than a 
    decent language.

    Might as well use fucking PHP...
    '''

    # First, we load the obsidian cache
    with open('.obsidian/cache', 'r') as f:
        source = json.load(f)
    
    # Obsidian uses numerous metadata segments for no
    # good reason, so we need to iterate over all of them
    # Otherwise, this is a typical unique-list-builder
    broken_links = []
    for segment in source['metadata']:
        for link in source['metadata'][segment]['links']:
            if link['link'] not in broken_links:
                broken_links.append(link['link'])

    # Similar unique-list-builder, only we're removing
    # extant links. As the source filenames are the 
    # canonical filename, stripping the '.md.' from files 
    # Obsidian knows about gets us the link name.
    for link in source['files'].keys():
        if link[:-3] in broken_links:
            broken_links.remove(link[:-3])

    if broken_links:
        with open('broken_links.md','w') as f:
            for link in broken_links:
                f.write('[[{}]]\n'.format(link))
    # Should have an 'else delete' here I guess but if 
    # I ever have a vault with no more links to make
    # then I'm clearly high as goosedick on something

if __name__ == '__main__':
    # TODO: Add some error checking maybe
    main()<commit_msg>Change broken links script to a markdown formattedlist<commit_after>#! /usr/local/bin/python3

import json

def main():
    ''' Creates a list of all the links that Obsidian
    knows about that do not have corresponding files
    yet.

    Written for personal use with no error checking.
    Obsidian's electron anyway, so if it ever opens
    up the chance of writing a plugin to do this
    it'll need done in Javascript rather than a 
    decent language.

    Might as well use fucking PHP...
    '''

    # First, we load the obsidian cache
    with open('.obsidian/cache', 'r') as f:
        source = json.load(f)
    
    # Obsidian uses numerous metadata segments for no
    # good reason, so we need to iterate over all of them
    # Otherwise, this is a typical unique-list-builder
    broken_links = []
    for segment in source['metadata']:
        for link in source['metadata'][segment]['links']:
            if link['link'] not in broken_links:
                broken_links.append(link['link'])

    # Similar unique-list-builder, only we're removing
    # extant links. As the source filenames are the 
    # canonical filename, stripping the '.md.' from files 
    # Obsidian knows about gets us the link name.
    for link in source['files'].keys():
        if link[:-3] in broken_links:
            broken_links.remove(link[:-3])

    if broken_links:
        with open('broken_links.md','w') as f:
            for link in broken_links:
                f.write('* [[{}]]\n'.format(link))
    # Should have an 'else delete' here I guess but if 
    # I ever have a vault with no more links to make
    # then I'm clearly high as goosedick on something

if __name__ == '__main__':
    # TODO: Add some error checking maybe
    main()
{'fraction_non_alphanumeric': 0.09101415775787344, 'fraction_numerical': 0.0017336030049118752, 'mean_word_length': 2.565396498455201, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1831941', 'n_tokens_mistral': 1000, 'n_tokens_neox': 942, 'n_words': 417}