5 from datetime import datetime
10 def timestamp() -> str:
11 t = datetime.fromtimestamp(time.time())
12 return t.strftime("%d/%b/%Y:%H:%M:%S%Z")
15 def describe_age_of_file(filename: str) -> str:
18 ts = os.stat(filename).st_ctime
21 return describe_duration(age)
22 except Exception as e:
26 def describe_age_of_file_briefly(filename: str) -> str:
29 ts = os.stat(filename).st_ctime
32 return describe_duration_briefly(age)
33 except Exception as e:
37 def describe_duration(age: int) -> str:
38 days = divmod(age, constants.seconds_per_day)
39 hours = divmod(days[1], constants.seconds_per_hour)
40 minutes = divmod(hours[1], constants.seconds_per_minute)
44 descr = f"{int(days[0]):d} days, "
48 descr = descr + f"{int(hours[0]):d} hours, "
50 descr = descr + "1 hour, "
52 descr = descr + "and "
54 descr = descr + "1 minute"
56 descr = descr + f"{int(minutes[0]):d} minutes"
60 def describe_duration_briefly(age: int) -> str:
61 days = divmod(age, constants.seconds_per_day)
62 hours = divmod(days[1], constants.seconds_per_hour)
63 minutes = divmod(hours[1], constants.seconds_per_minute)
67 descr = f"{int(days[0]):d}d "
69 descr = descr + f"{int(hours[0]):d}h "
70 descr = descr + f"{int(minutes[0]):d}m"
74 # x = describe_age_of_file_briefly("pages/clock_10_none.html")