Wednesday, December 13, 2023

Tonie Weather

 So my son loves his tonie so much for listening to his favorite shows: blog post about that project here


I thought it would be cool to make one of his tonies tell him the weather for the day. So I threw this script together to generate a "text to speech" weather forecast for the day, and clothing recommendations for him to dress himself.

It runs every day to get the current weather, and uses the hourly high/lows and precipitation data to recommend what to wear. He wakes up in the morning, puts the yeti tonie on the box, and then knows exactly what to wear for the day.

He loves it.




Here is the code: https://github.com/spiffomatic64/tonie_sync/blob/master/tonie_weather.py


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from noaa_sdk import NOAA
import json
from gtts import gTTS
import shutil
from pprint import pprint
from datetime import datetime, timedelta


def get_temp(temp, low):
    temps = {100: "Very hot, Wear a Tshirt and shorts",
             85: "Hot, Wear a Tshirt and shorts",
             75: "Warm, Wear a Tshirt and shorts",
             65: "Nice, Wear a Tshirt and shorts",
             50: "Cool, Wear a Tshirt and pants",
             40: "Cold, Wear a Long Sleeves shirt and pants",
             30: "Very Cold, Wear a Long Sleeves shirt and pants"}

    for t in temps:
        if temp > t:
            if low < 65:
                temp_data = temps[t].replace("shorts","pants")
            return temp_data


def get_forcast(forecast_data, hourly_data):
    json_formatted_str = json.dumps(forecast_data, indent=2)
    print(json_formatted_str)

    tomorrow = datetime.now() + timedelta(1)
    tomorrow_string = tomorrow.strftime("%Y-%m-%d")
    # print(tomorrow_string)
    max = 0
    min = 100
    for hour_data in hourly_data:
        if hour_data['startTime'][:10] == tomorrow_string:
            hour = int(hour_data['startTime'][11:13])

            if hour > 6 and hour < 17:
                # print(hour)
                if hour_data['temperature'] > max:
                    max = hour_data['temperature']
                if hour_data['temperature'] < min:
                    min = hour_data['temperature']

    print(f"High: {max} Low: {min}")
    temp = get_temp(forecast_data['temperature'], min)
    forcast_string = (f"{forecast_data['name']} will be {temp}. " +
                      f"The forecast is {forecast_data['detailedForecast']} " +
                      f"The Low will be {min}")
    return forcast_string


n = NOAA()
res = n.get_forecasts('19067', 'US', type="forecast")
res2 = n.get_forecasts('19067', 'US', type="forecastHourly")
forecast = get_forcast(res[2], res2)
print(forecast)

myobj = gTTS(text=forecast, lang="en", slow=True)

# Saving the converted audio in a mp3 file named
# welcome
path = "I:\\audio\\weather"
filename = "weather"
ext = "mp3"

myobj.save(f"{path}\\{filename}0.{ext}")
for num in range(1, 3):
    shutil.copy(f"{path}\\{filename}0.{ext}", f"{path}\\{filename}{num}.{ext}")

More custom action figures

 When your son wants an action figure that doesn't exist... You 3d print it! Here is what it looks like in the game. And here is what I ...