Skip to content

Commit 5b9f9ae

Browse files
committed
add api weather notifications sms
1 parent 13ac15a commit 5b9f9ae

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

WeatherNotification/main.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
import requests
2+
import os
3+
from twilio.rest import Client
24

3-
end_point = "https://api.openweathermap.org/data/2.5/forecast"
4-
api_key = "API-KEY"
5+
twilio_account_sid = os.environ['TWILIO_ACCOUNT_SID']
6+
twilio_auth_token = os.environ['TWILIO_AUTH_TOKEN']
7+
openweather_end_point = "https://api.openweathermap.org/data/2.5/forecast"
8+
openweather_api_key = os.environ['OPEN_WEATHER_AUTH_TOKEN']
59

610
weather_params = {
7-
"lat": 40.416775,
8-
"lon": -3.703790,
9-
"appid": api_key,
11+
"lat": 37.270969,
12+
"lon": -79.941429,
13+
"appid": openweather_api_key,
1014
"cnt": 4
1115
}
1216

13-
r = requests.get(end_point, params=weather_params)
17+
r = requests.get(openweather_end_point, params=weather_params)
1418
r.raise_for_status()
1519
weather_data = r.json()
1620

1721
id_weather_list = weather_ids = [x["weather"][0]["id"] for x in weather_data["list"] if x["weather"][0]["id"] < 700]
1822

1923
if len(id_weather_list) >= 1:
20-
print("Bring an umbrella")
24+
client = Client(twilio_account_sid, twilio_auth_token)
25+
26+
message = client.messages \
27+
.create(
28+
body="It's going to rain today! Remember to bring an ☔.",
29+
from_='+twilio-phone',
30+
to='+my-verified-phone'
31+
)
32+
print(message.sid)

0 commit comments

Comments
 (0)