-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRainCheck code.py
More file actions
37 lines (29 loc) · 988 Bytes
/
RainCheck code.py
File metadata and controls
37 lines (29 loc) · 988 Bytes
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
import requests
from twilio.rest import Client
OMW_endpoint = "https://api.openweathermap.org/data/2.5/forecast"
api_key = "you open weather map api key"
account_sid = "you twilio account sid"
auth_token = "your twilio auth token"
weather_params = {
"lat":28.474388,
"lon":77.503990,
"appid":api_key,
"cnt":4
}
response = requests.get(OMW_endpoint, params=weather_params)
response.raise_for_status()
weather_data = response.json()
#print(weather_data["list"][0]["weather"][0]["id"])
will_rain = False
for hour_data in weather_data["list"]:
condition_code = hour_data["weather"][0]["id"]
if int(condition_code) < 700:
will_rain = True
if will_rain:
client = Client(account_sid, auth_token)
message = client.messages.create(
body="It's Gonna rain today. So remember to bring an Umbrella! ⛈️☂️",
from_="+19123616563",
to="+919289419730",
)
print(message.status)