123456789101112131415161718192021222324252627282930313233343536373839404142 |
- # This is part of Kaylee
- # -- this code is licensed GPLv3
- # Copyright 2015-2017 Clayton G. Hobbs
- # Portions Copyright 2013 Jezra
-
- """Helper utilities for Kaylee plugins"""
-
- import time
-
-
- def format_temperature(temperature, precision, unit='degrees Fahrenheit'):
- """Format a temperature for the TTS system"""
- return f'{temperature:.{precision}f} {unit}'
-
- def format_percent(value):
- """Format a floating-point value as a percentage for the TTS system"""
- return f'{100*value:.0f} percent'
-
- def format_time(seconds=None):
- """Format a time in seconds since the Epoch for the TTS system"""
- t = time.localtime(seconds)
-
- # Format each part of the time to be pronounced nicely
- hour = time.strftime('%I', t)
- if hour[0] == '0':
- hour = hour[1]
-
- minute = time.strftime('%M', t)
- if minute[0] == '0':
- if minute[1] == '0':
- minute = "o'clock"
- else:
- minute = 'O' + minute[1]
-
- ante_post = time.strftime('%p', t)
- if ante_post[0] == 'A':
- ante_post = 'AE ' + ante_post[1]
- elif ante_post[0] == 'P':
- ante_post = 'P ' + ante_post[1]
-
- # Put the parts together
- return f'{hour} {minute} {ante_post}'
|