You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.3 KiB
76 lines
2.3 KiB
from pathlib import Path, PurePosixPath
|
|
import os
|
|
currentDirectory = os.getcwd()
|
|
currentDirHC = "/home/nclanceman/tools/weather"
|
|
|
|
# currentDirectory = PurePosixPath(Path.cwd())
|
|
|
|
adjectives = ["severe", "scattered", "partly", "mostly", "light", "heavy"]
|
|
clearWords = ["clear", "sunny"]
|
|
rainWords = ["rain", "showers"]
|
|
fogWords = ["fog", "mist", "smoke"]
|
|
windWords = ["wind", "windy", "gusts"]
|
|
cloudWords = ["cloudy", "overcast"]
|
|
stormWords = ["thunderstorms", "thunderstorm"]
|
|
|
|
|
|
def parseDescription(desc):
|
|
# Parse a weather description by returning the first
|
|
# "weather word" in a NWS description.
|
|
# parsed = ((desc.lower()).split("/")).split(" ")
|
|
parsed = ((desc.lower()).split(" "))
|
|
|
|
for i in parsed:
|
|
if i in adjectives:
|
|
continue
|
|
elif i in clearWords:
|
|
return "clear"
|
|
elif i in rainWords:
|
|
return "rain"
|
|
elif i in fogWords:
|
|
return "fog"
|
|
elif i in windWords:
|
|
return "wind"
|
|
elif i in cloudWords:
|
|
return "cloudy"
|
|
elif i in stormWords:
|
|
return "thunderstorm"
|
|
else:
|
|
return "clear"
|
|
|
|
return ""
|
|
|
|
|
|
def imageSelector(desc, timeOfDay):
|
|
result = ""
|
|
|
|
match desc:
|
|
case "clear":
|
|
if timeOfDay == "day":
|
|
result = os.path.join(
|
|
currentDirectory, 'smallIcons', 'clear-day-small.png')
|
|
else:
|
|
result = os.path.join(
|
|
currentDirectory, 'smallIcons', 'clear-night-small.png')
|
|
case "cloudy":
|
|
if timeOfDay == "day":
|
|
result = os.path.join(
|
|
currentDirectory, 'smallIcons', 'overcast-day-small.png')
|
|
else:
|
|
result = os.path.join(
|
|
currentDirectory, 'smallIcons', 'overcast-night-small.png')
|
|
case "wind":
|
|
result = os.path.join(
|
|
currentDirectory, 'smallIcons', 'wind-small.png')
|
|
case "thunderstorm":
|
|
result = os.path.join(
|
|
currentDirectory, 'smallIcons', 'thunderstorms-rain-small.png')
|
|
|
|
case "rain":
|
|
result = os.path.join(
|
|
currentDirectory, 'smallIcons', 'rain-small.png')
|
|
case _:
|
|
result = os.path.join(
|
|
currentDirectory, 'smallIcons', 'code-red-small.png')
|
|
|
|
return result
|
|
|