Finish daemonizing clock

This commit is contained in:
Shav Kinderlehrer 2024-06-22 23:11:51 -04:00
parent cb9e38d97b
commit 659fb7ad43
3 changed files with 15 additions and 81 deletions

View File

@ -34,7 +34,8 @@ number_map = {
class Clock: class Clock:
def __init__(self): def __init__(self):
pass time_prompt = self.serialize_time(datetime.now())
self.time = self.generate_rhyme(time_prompt)
def serialize_time_part(self, part): def serialize_time_part(self, part):
part_string = "" part_string = ""
@ -83,5 +84,6 @@ class Clock:
now = datetime.now() now = datetime.now()
then = datetime(now.year, now.month, now.day, now.hour, now.minute + 1, 0) then = datetime(now.year, now.month, now.day, now.hour, now.minute + 1, 0)
seconds_until = (then - now).total_seconds() seconds_until = (then - now).total_seconds()
print(seconds_until) sleep(seconds_until)
sleep(1) time_prompt = self.serialize_time(datetime.now())
self.time = self.generate_rhyme(time_prompt)

View File

@ -1,87 +1,19 @@
from weather import Weather from weather import Weather
from time import sleep
from clock import Clock from clock import Clock
from openai import OpenAI from time import sleep
from datetime import datetime
number_map = {
"0": "o'clock",
"1": "one",
"2": "two",
"3": "three",
"4": "four",
"5": "six",
"6": "six",
"7": "seven",
"8": "eight",
"9": "nine",
"10": "ten",
"11": "eleven",
"12": "twelve",
"13": "thirteen",
"14": "fourteen",
"15": "fifteen",
"16": "sixteen",
"17": "seventeen",
"18": "eighteen",
"19": "nineteen",
"20": "twenty",
"30": "thirty",
"40": "forty",
"50": "fifty",
}
def serialize_time_part(part):
part_string = ""
if part in number_map:
part_string += number_map[part]
else:
tens_str = number_map[f"{part[0]}0"]
ones_str = number_map[part[1]]
part_string += f"{tens_str}-{ones_str}"
return part_string
def serialize_time(time):
hour = str(time.hour)
if time.hour > 12:
hour = str(time.hour - 12)
hour = serialize_time_part(hour)
minute = str(time.minute)
if time.minute < 10:
minute = f"o'{serialize_time_part(minute)}"
else:
minute = serialize_time_part(minute)
time_string = f"{hour} {minute}"
return time_string
def generate_rhyme(time):
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "user",
"content": f"Finish this sentence about the time with a rhyme. It's {time}, ",
}
],
)
rhyme = response.choices[0].message.content
return f"It's {time}, {rhyme}"
def main(): def main():
# weather_manager = Weather() weather_manager = Weather()
# weather_manager.start_update_loop() weather_manager.start_update_loop()
# use_time = datetime.now()
# serialized_time = serialize_time(use_time)
# sentence = generate_rhyme(serialized_time)
clock_manager = Clock() clock_manager = Clock()
clock_manager.start_update_loop() clock_manager.start_update_loop()
sleep(1000)
while True:
print(clock_manager.time)
print(weather_manager.weather["data"]["values"]["temperature"])
sleep(10)
if __name__ == "__main__": if __name__ == "__main__":
main() main()