-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathmain.py
41 lines (34 loc) · 1.12 KB
/
main.py
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
import requests
import os
from twilio.rest import Client
from twilio.http.http_client import TwilioHttpClient
OWM_Endpoint = "https://api.openweathermap.org/data/2.5/onecall"
api_key = "8f14ac1ce7426fef035aa2a985c43017"
account_sid = "******************"
auth_token = "******************"
weather_params = {
"lat": 55.740280,
"lon": 52.398109,
"appid": api_key,
"exclude": "current, minutely, daily"
}
response = requests.get(OWM_Endpoint, params=weather_params)
response.raise_for_status()
weather_data = response.json()
weather_slice = weather_data["hourly"][:12]
will_rain = False
for hour_data in weather_slice:
condition_code = hour_data["weather"][0]["id"]
if int(condition_code) < 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, http_client=proxy_client)
message = client.messages \
.create(
body="It's going to rain today. Remember to bring an ☔️",
from_="+*********",
to="+*********"
)
print(message.status)