Skip to content

Commit 2c01c7f

Browse files
authored
Create main.py
1 parent 12ee018 commit 2c01c7f

File tree

1 file changed

+35
-0
lines changed
  • Weather Alert Notification Sender

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Rain Alert API
2+
import requests
3+
from twilio.rest import Client
4+
5+
account_sid = ""
6+
auth_token = ""
7+
8+
9+
end_point = "https://api.openweathermap.org/data/2.5/forecast"
10+
api_key = ""
11+
12+
weather_params = {
13+
"lat": 29.749020,
14+
"lon": -94.834953,
15+
"appid": api_key,
16+
"cnt": 4
17+
}
18+
19+
response = requests.get(end_point, params=weather_params)
20+
response.raise_for_status()
21+
weather_data = response.json()
22+
# print(weather_data["list"][0]["weather"][0]["id"])
23+
will_rain = False
24+
for hour_data in weather_data["list"]:
25+
condition_code = hour_data["weather"][0]["id"]
26+
if int(condition_code) < 700:
27+
will_rain = True
28+
if will_rain:
29+
client = Client(account_sid, auth_token)
30+
message = client.messages.create(
31+
body="It's going to rain today. Remember to bring an Umbrella ☔",
32+
from_='',
33+
to=''
34+
)
35+
print(message.status)

0 commit comments

Comments
 (0)