-
-
Save devinzuck/e70d08d64fcbe46c64f33754695973c9 to your computer and use it in GitHub Desktop.
Revisions
-
pauljacobson revised this gist
Nov 22, 2020 . No changes.There are no files selected for viewing
-
pauljacobson created this gist
Nov 22, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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:,}"))