Count of shots taken

good evening, maybe it can be useful to someone.
I was curious to know how many shots I collected at each session so I created this script to launch after the sequence which counts the new fit files and saves the count in a string which I then send to myself via telegram

from pathlib import Path
from datetime import datetime, timedelta
def count_fit_files_last_12_hours(directory):
count = 0
now = datetime.now()
for file_path in Path(directory).rglob(“*.fit”):
# Ottieni il tempo di modifica del file
modification_time = datetime.fromtimestamp(file_path.stat().st_mtime)
# Verifica se il file è stato modificato nelle ultime 12 ore
if now - modification_time <= timedelta(hours=12):
count += 1
# Stampa di debug per vedere il percorso di ciascun file .fit
# print(file_path)
return count

Inserisci il percorso della directory qui

directory_to_check = “your path”
fit_file_count_last_12_hours = count_fit_files_last_12_hours(directory_to_check)
print(f"Numero di file *.fit nelle ultime 12 ore nella directory e sottocartelle: {fit_file_count_last_12_hours}")

WhatsApp Image 2024-01-29 at 15.58.07

3 Likes