X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=utils.py;fp=utils.py;h=fb22e4dd052acfa4731dc62a30b928084cb00051;hb=5e241dc47e497c547463cecc07946ea6882835a7;hp=51a29e7680400268ea09ecda867df6ad41105545;hpb=41262fc75551d35bcc9979011078b0e5b4e7b36a;p=kiosk.git diff --git a/utils.py b/utils.py index 51a29e7..fb22e4d 100644 --- a/utils.py +++ b/utils.py @@ -3,9 +3,11 @@ import os import constants from datetime import datetime + def timestamp(): t = datetime.fromtimestamp(time.time()) - return t.strftime('%d/%b/%Y:%H:%M:%S%Z') + return t.strftime("%d/%b/%Y:%H:%M:%S%Z") + def describe_age_of_file(filename): try: @@ -16,6 +18,7 @@ def describe_age_of_file(filename): except Exception as e: return "?????" + def describe_age_of_file_briefly(filename): try: now = time.time() @@ -25,39 +28,42 @@ def describe_age_of_file_briefly(filename): except Exception as e: return "?????" + def describe_duration(age): days = divmod(age, constants.seconds_per_day) hours = divmod(days[1], constants.seconds_per_hour) minutes = divmod(hours[1], constants.seconds_per_minute) descr = "" - if (days[0] > 1): + if days[0] > 1: descr = "%d days, " % days[0] - elif (days[0] == 1): + elif days[0] == 1: descr = "1 day, " - if (hours[0] > 1): + if hours[0] > 1: descr = descr + ("%d hours, " % hours[0]) - elif (hours[0] == 1): + elif hours[0] == 1: descr = descr + "1 hour, " - if (len(descr) > 0): + if len(descr) > 0: descr = descr + "and " - if (minutes[0] == 1): + if minutes[0] == 1: descr = descr + "1 minute" else: descr = descr + ("%d minutes" % minutes[0]) return descr + def describe_duration_briefly(age): days = divmod(age, constants.seconds_per_day) hours = divmod(days[1], constants.seconds_per_hour) minutes = divmod(hours[1], constants.seconds_per_minute) descr = "" - if (days[0] > 0): + if days[0] > 0: descr = "%dd " % days[0] - if (hours[0] > 0): + if hours[0] > 0: descr = descr + ("%dh " % hours[0]) descr = descr + ("%dm" % minutes[0]) return descr -#x = describe_age_of_file_briefly("pages/clock_10_none.html") -#print x + +# x = describe_age_of_file_briefly("pages/clock_10_none.html") +# print x