-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.py
34 lines (26 loc) · 1.02 KB
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# A script to find out how many notes are there, how many characters in each notes and the total of the; and the longest notes.
import heapq
import os
def stats(directory):
total_sum = 0
alls = []
count = 0
for root, dirs, files in os.walk(directory):
for filename in files:
if filename.endswith(".md") or filename.endswith(".mdx"):
file_path = os.path.join(root, filename)
count += 1
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()
char_sum = len(content)
total_sum += char_sum
alls.append((-char_sum, filename))
print(f"Note: {file_path}, Characters: {char_sum}")
print(f"\nTotal Characters in All Notes: {total_sum}")
print(f"Total notes: {count}")
print(f"\nLongest notes:")
heapq.heapify(alls)
for _ in range(5):
c, n = heapq.heappop(alls)
print(f" Character: {-c} | {n}")
stats("docs")