Compare commits

..

3 Commits

Author SHA1 Message Date
bod
44b7d2ef0a v1.0.0 baby 2025-01-14 12:06:20 +00:00
b8d3f3b943 Merge pull request 'Fix for the timezone issue' (#2) from issue_1 into main
Reviewed-on: billie/fuzzy_clock#2
2023-03-30 23:35:07 +01:00
62ce77fdf4 Switched to using datetime.now() calls 2023-03-30 23:31:03 +01:00

View File

@@ -1,92 +1,48 @@
#!/usr/bin/python3 #!/usr/bin/env python3
# Name: Fuzzy Clock # Name: Fuzzy Clock
# Version: 0.2.1 # Version: 1.0.0
# Last Updated: 7/12/22 # Last Updated: 14/1/25
# Author: Billie O'Dwyer # Author: Eibhlín O'Dwyer
# Email: billie@odwyer.xyz # Email: eibhlin@beod.co.uk
# Description: A script that returns the time in a speech like manner, for example 'quarter past two' # Description: A script that returns the time in a speech like manner, for example 'quarter past two'
import time from datetime import datetime
def return_hour(n): def get_fuzzy_time(hour, minute):
# Determine what the current hour to return is """ Turn a 24-hour clock output into a human-speech like string.
if n == 1 or n == 13: """
return "one" # Dictionary defining integers:strings
if n == 2 or n == 14: hours = ["twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven"]
return "two"
if n == 3 or n == 15:
return "three"
if n == 4 or n == 16:
return "four"
if n == 5 or n == 17:
return "five"
if n == 6 or n == 18:
return "six"
if n == 7 or n == 19:
return "seven"
if n == 8 or n == 20:
return "eight"
if n == 9 or n == 21:
return "nine"
if n == 10 or n == 22:
return "ten"
if n == 11 or n == 23:
return "eleven"
if n == 12 or n == 0 or n == 24:
return "twelve"
def to_or_past(n): # Dictionary definining integer ranges:strings
# Determine whether to return to, past, or other minutes = {
if 1 <= n <= 32: (3, 7, "five"), (53, 57, "five"),
return "past" (8, 12, "ten"), (48, 52, "ten"),
if 33 <= n <= 57: (13, 17, "quarter"), (43, 47, "quarter"),
return "to" (18, 22, "twenty"), (38, 42, "twenty"),
(23, 27, "twenty-five"), (33, 37, "twenty-five"),
(28, 32, "half")
}
def return_minute(n): # Iterate through minute dictionary to find the next entry which contains the present minute, otherwise return None
# Determine what the current minute to return is minute_phrase = next((phrase for start, end, phrase in minutes if start <= minute <= end), None)
if 3 <= n <= 7 or 53 <= n <= 57:
return "five"
if 8 <= n <= 12 or 48 <= n <= 52:
return "ten"
if 13 <= n <= 17 or 43 <= n <= 47:
return "quarter"
if 18 <= n <= 22 or 38 <= n <= 42:
return "twenty"
if 23 <= n <= 27 or 33 <= n <= 37:
return "twenty-five"
if 28 <= n <= 32:
return "half"
def cat(h,m): # Put it all together and return the phrase we want
# Put it all together if minute_phrase:
# HALF if minute in {58, 59}:
if 28 <= m <= 32: return f"{hours[(hour +1)] % 12} o'clock"
return return_minute(m) + " " + to_or_past(m) + " " + return_hour(h) if minute in {0, 1, 2}:
return f"{hours[hour] % 12} o'clock"
if 3 <= minute <= 32: # Past
return f"{minute_phrase} past {hours[hour % 12]}"
if 33 <= minute <= 57: # To
return f"{minute_phrase} to {hours[(hour + 1) % 12]}"
# PAST # Get current time
if 3 <= m <= 27:
return return_minute(m) + " " + to_or_past(m) + " " + return_hour(h)
# TO now = datetime.now()
if 33 <= m <= 57: hour, minute = now.hour, now.minute
return return_minute(m) + " " + to_or_past(m) + " " + return_hour(h+1)
# OCLOCK # Output the fuzzy time
if m in [58, 59]: print(get_fuzzy_time(hour, minute))
return return_hour(h+1) + " o'clock"
if m in [0, 1, 2]:
return return_hour(h) + " o'clock"
h = time.gmtime()[3]
m = time.gmtime()[4]
print(cat(h,m))
# Is it o'clock?
# Is it 12?
# Is it after or before?
# What is it after or before?
# https://github.com/SarthakU/fuzzy-clock/blob/master/fuzzy.py <- is a good resouce to take inspiration from