Created
February 21, 2022 14:58
-
-
Save Jithender5913/d2b9d9a4cb9d2ac75b09131041667904 to your computer and use it in GitHub Desktop.
Rain alert project using Twilio API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from twilio.rest import Client | |
API_KEY = "xxx" | |
OWM_endpoint = "https://api.openweathermap.org/data/2.5/onecall" | |
weather_parameters = { | |
"lat": 35.652832, | |
"lon": 139.839478, | |
"appid": API_KEY, | |
"exclude": "current,minutely,daily" | |
} | |
response = requests.get(OWM_endpoint, params=weather_parameters) | |
response.raise_for_status() | |
weather_data = response.json() | |
print(weather_data["hourly"][0]["weather"][0]["id"]) | |
weather_slice = weather_data["hourly"][0:12] | |
print(weather_slice) | |
will_rain = False | |
for hour_data in weather_slice: | |
id_list = hour_data["weather"][0]["id"] | |
if int(id_list) < 700: | |
will_rain = True | |
account_sid = "xxx" | |
auth_token = "xxx" | |
if will_rain: | |
client = Client(account_sid, auth_token) | |
message = client.messages \ | |
.create( | |
body="Its going to rain💧.Bring your own ☂☂.", | |
from_='+1XXX', | |
to='+XXX' | |
) | |
print(message.status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment