Skip to content

Instantly share code, notes, and snippets.

@devinzuck
Forked from pauljacobson/vault_stats.py
Created July 20, 2021 21:16
Show Gist options
  • Select an option

  • Save devinzuck/e70d08d64fcbe46c64f33754695973c9 to your computer and use it in GitHub Desktop.

Select an option

Save devinzuck/e70d08d64fcbe46c64f33754695973c9 to your computer and use it in GitHub Desktop.

Revisions

  1. @pauljacobson pauljacobson revised this gist Nov 22, 2020. No changes.
  2. @pauljacobson pauljacobson created this gist Nov 22, 2020.
    49 changes: 49 additions & 0 deletions vault_stats.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    # Huge thanks to Rythm for the original code
    # that I adapted for this script
    # Source: https://j.mp/2UPeDJh

    import os.path
    import datetime

    FILE_PATH = "/path/to/vault/directory/"
    TODAY = datetime.datetime.today()
    LAST_UPDATE = "{:%A %d %B, %Y at %H:%M}".format(TODAY)


    def thousands(big_number):
    """Reformat big numbers with thousands separators"""
    rf_number = "{:,}".format(big_number)
    return rf_number


    markdownFiles = []
    all_files = []
    words = 0

    for dirpath, dirnames, filenames in os.walk(FILE_PATH):
    for filename in [f for f in filenames if f.endswith(".md")]:
    markdownFiles.append(os.path.join(dirpath, filename))

    # This is probably unnecessary duplication
    for dirpath, dirnames, filenames in os.walk(FILE_PATH):
    for filename in [af for af in filenames]:
    all_files.append(os.path.join(dirpath, filename))

    for file in markdownFiles:
    with open(file, "r") as f:
    words += len(f.read().split())


    with open(FILE_PATH + "./_vault stats.md", "w") as f:
    f.write(
    f"""# Vault Statistics
    This vault currently contains **{thousands(words)}** words in **{thousands(len(markdownFiles))}** Markdown files.
    The vault contains **{thousands(len(all_files))}** files, in total.
    _Last updated on **{LAST_UPDATE}**_
    """
    )

    print(str(f"{words:,}"))