Add year summary script
parent
d300f90298
commit
b220032d6b
@ -0,0 +1,73 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from random import randint
|
||||
from datetime import datetime
|
||||
|
||||
thisyear = datetime.now().strftime("%Y")
|
||||
home = str(Path.home())
|
||||
stats = []
|
||||
|
||||
def iterate(category,action,year=thisyear,date=False):
|
||||
basedir = home + "/Documents/drive/org/journal/" + str(year)
|
||||
count = 0
|
||||
print("* " + category)
|
||||
print("** " + action)
|
||||
month = 1
|
||||
while True:
|
||||
if month < 13:
|
||||
if month < 10:
|
||||
monthname = basedir + "/0" + str(month)
|
||||
else:
|
||||
monthname = basedir + "/" + str(month)
|
||||
if os.path.exists(monthname):
|
||||
for file in sorted(os.listdir(monthname)):
|
||||
filename = monthname + "/" + str(file)
|
||||
if filename.endswith(".org"):
|
||||
with open(filename, "r") as file:
|
||||
lines = file.readlines()
|
||||
for num, line in enumerate (lines, 0):
|
||||
if str("** " + str(action)) in line:
|
||||
num += 1
|
||||
if num + 1 < len(lines):
|
||||
if "*** " in lines[num]:
|
||||
while True:
|
||||
if "*** " in lines[num]:
|
||||
if date == True:
|
||||
print(lines[num].strip() + " " + lines[0].strip())
|
||||
else:
|
||||
print(lines[num].strip())
|
||||
count += 1
|
||||
else:
|
||||
break
|
||||
if num + 1 < len(lines):
|
||||
num += 1
|
||||
else:
|
||||
break
|
||||
else:
|
||||
break
|
||||
else:
|
||||
break
|
||||
else:
|
||||
if num < len(lines):
|
||||
if "*** " in lines[num]:
|
||||
if date == True:
|
||||
print(lines[num].strip() + " " + lines[0].strip())
|
||||
else:
|
||||
print(lines[num].strip())
|
||||
count += 1
|
||||
else:
|
||||
break
|
||||
else:
|
||||
break
|
||||
month += 1
|
||||
stats.append(count)
|
||||
|
||||
def yeargrab(year=thisyear):
|
||||
iterate("books","read",year)
|
||||
iterate("films","watched",year)
|
||||
print("* stats")
|
||||
print("** books read: " + str(stats[0]))
|
||||
print("** films watched: " + str(stats[1]))
|
||||
|
||||
if __name__ == "__main__":
|
||||
yeargrab()
|
Loading…
Reference in New Issue