-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathweather.py
More file actions
executable file
·99 lines (71 loc) · 3.32 KB
/
weather.py
File metadata and controls
executable file
·99 lines (71 loc) · 3.32 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# -*- coding: utf-8-*-
import random
import re
from datetime import datetime
import pywapi
WORDS = [""]
PRIORITY = 4
def temperatureSuggestion(temp):
global string
string = ""
if 0 > temp :
string = "It's freezing cold so I'd suggest warm clothes as well as a winter coat. "
elif (0<=temp) and (temp<5):
string = "It's rather cold so I'd suggest warm clothes.One might consider a winter coat. "
elif (5<=temp) and (temp< 16):
string = "It's rather cold today so I'd suggest moderatly long trousers and a pullover . As for a coat, a spring jacket should suffice. "
elif (16<=temp)and (temp<22):
string = "It's rather fresh today so I'd suggest long trouses and a t-shirt. Maybe a jacket is needed. "
elif (22<=temp)and (temp<25):
string = "It's hot today. I'd suggest shorts and a t-shirt. "
elif (25<=temp)and (temp<30):
string = "It's very hot today. I'd suggest wearing the least amount of clothes you can. "
elif 30 <= temp:
string = "It's blazing today. I'd go naked if I were you. "
string +=". "
return string
def rain(list):
date = datetime.now().day
integer = 0
loc = 0
string = ""
for day in list:
if str(date) in day["date"].lower():
loc = integer
integer +=1
likelyhood_string = list[loc]["day"]["chance_precip"]
likelyhood = int(likelyhood_string)
if (0 <= likelyhood) and (likelyhood<= 30):
string += "It should not rain , so don't bother taking an umbrella with you."
elif (30 < likelyhood) and (likelyhood<= 50):
string += "Keep in mind though that there is a slight chance of rain today, so maybe take an umbrella with you, when you leave."
elif(50< likelyhood) and (likelyhood <65):
string += "Keep in mind though that it's probably going to rain today, so taking an umbrella would be a smart idea."
else:
string += "Keep in mind though that it's definitly going to rain today, so do take an umbrella."
return string
def handle(text, mic, profile):
weather_com_result = pywapi.get_weather_from_weather_com('SZXX0728')
weather_status = weather_com_result['current_conditions']['text']
weather_felttemp = weather_com_result['current_conditions']['feels_like']
weather = "The weather conditions are "+weather_status+" with a felt temperature of "+ weather_felttemp+ " degrees Celsius. "
if ("clothes" in text.lower()) or ("wear" in text.lower()):
chance_rain = rain(weather_com_result['forecasts'])
felttemp_int = int(weather_felttemp)
weather_suggestion = temperatureSuggestion(felttemp_int)
weather_suggestion += chance_rain
mic.say(weather_suggestion)
elif ("hot" in text.lower()) or ("temperature" in text.lower()) or ("cold" in text.lower()):
mic.say("There's currently a felt temperature of "+weather_felttemp+" degrees Celsius.")
elif "rain" in text.lower():
rainprop = rain(weather_com_result['forecasts'])
mic.say(rainprop)
else :
mic.say(weather)
def isValid(text):
"""
Returns True if the input is related to the meaning of life.
Arguments:
text -- user-input, typically transcribed speech
"""
return bool(re.search(r'\b((rain|weather|wear|clothes|hot|cold|temperature))\b', text, re.IGNORECASE))