Ejemplo n.º 1
0
def main():
    bear_notes = [BearNote(note) for note in bear_api.notes()]
    notes = {note.title: note for note in bear_notes}

    for title, note in notes.items():
        notes[title].text = replace_links(note.text)

    backreferences, _ = find_all_links(notes)

    print("Orphaned notes:\n")
    for note_id, note in notes.items():
        if "#_index" in note.text:
            continue

        note_back_refs = backreferences[note_id]
        note_text = note.text
        if note_back_refs:
            note_text = ''.join(text_lines(note, backref_links=note_back_refs))
        elif not '#_daily' in note.text:
            if note_id != '':
                print("[[" + note_id + "]]")
            else:
                print("[No title](bear://x-callback-url/open-note?id=" +
                      note.uid + ")")

        bear_api.replace_note_text(note, note_text)
Ejemplo n.º 2
0
def main_test():
    bear_notes = [BearNote(note) for note in bear_api.notes()]
    notes = {note.uid: note for note in bear_notes}
    backreferences, _ = find_all_links(notes)
    for note_id, note in notes.items():
        note_back_refs = backreferences[note_id]
        if note_back_refs:
            new_note_content = ''.join(
                text_lines(note, backref_links=note_back_refs))
            bear_api.replace_note_text(note, new_note_content)
Ejemplo n.º 3
0
def main():
    notes = [BearNote(n) for n in bear_api.notes()]
    backreferences, out_links = find_all_links(notes)
    backreferences = filter_out_existing_links(backreferences, out_links)
    # backreferences = filter_out_self_links(backreferences, out_links)
    nb_links_inserted = 0
    for note in notes:
        try:
            nb_links_inserted += add_backreferences_to_note(note, backreferences, out_links)
        except KeyError:
            pass

    print(f"Inserted {nb_links_inserted} new links to your notes.")
Ejemplo n.º 4
0
            were found. If no backreference was found they are just added
            at the very end of the note. (Maybe we can append them before the tags,
            just like add-text with append does in the Bear API?
            I prefer it like this personally)
    """
    marker = BACKREFERENCES_SECTION + BACKREFERENCES_INTRO_TEXT
    text = note.text

    try:
        text = text[:text.index(marker)]
    except Exception:
        text = text

    return text + markdown_link_list(sorted(backref_links))


if __name__ == "__main__":
    bear_notes = [BearNote(note) for note in bear_api.notes()]
    titles = []
    valid = True
    for n in bear_notes:
        if n.title in titles:
            print("Duplicated!", n.title)
            print("[Fix me](bear://x-callback-url/open-note?id=" + n.uid + ")")
            valid = False

        titles.append(n.title)

    if valid:
        main()