-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 35 - Rain Alert SMS
46 lines (35 loc) · 1.15 KB
/
Day 35 - Rain Alert SMS
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
#Day 35: Create a rain alert application so that you will receive a notification daily with a reminder to bring an umbrella if it rains.
import requests
import os
from twilio.rest import Client
from twilio.http.http_client import TwilioHttpClient
MY_LAT = 1.352083
MY_LONG = 103.819839
API_KEY = "69f04e4613056b159c2761a9d9e664d2"
ACCOUNT_SID = "[account_sid here]"
AUTH_TOKEN = "[auth_tocken here]"
parameters = {
"lat": MY_LAT,
"lon": MY_LONG,
"appid": API_KEY,
"exclude": "current,minutely,daily"
}
response = requests.get(url="https://api.openweathermap.org/data/2.5/onecall", params=parameters)
response.raise_for_status()
data = response.json()
will_rain = False
for x in range(13):
id = data["hourly"][x]["weather"][0]["id"]
if id < 700:
will_rain = True
if will_rain:
proxy_client = TwilioHttpClient()
proxy_client.session.proxies = {'https': os.environ['https_proxy']}
client = Client(ACCOUNT_SID, AUTH_TOKEN)
message = client.messages \
.create(
body="Bring an umbrella ☂",
from_='[phone_number here]',
to='[phone_number here]'
)
print(message.status)