-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (34 loc) · 1.24 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
42
43
44
45
import requests
from twilio.rest import Client
ENDPOINT = "https://api.openweathermap.org/data/2.5/onecall"
API_KEY = "" # ENTER YOUR TWILIO API KEY
account_sid = "" # ENTER YOUR TWILIO ACCOUNT SID
auth_token = "" # ENTER YOUR TWILIO AUTH TOKEN
TWILIO_NUMBER = "+1123456789" # ENTER YOUR TWILIO GENERATED NUMBER
MOBILE_NUMBER = "+1123456789" # ENTER YOUR MOBILE NUMBER
parameters = {
"lat":19.0144, # ENTER YOUR LATITUDE
"lon":72.8479, # ENTER YOUR LONGITUDE
"appid":API_KEY,
"exclude":"current,minutely,daily"
}
response = requests.get(url=ENDPOINT, params=parameters)
response.raise_for_status()
data = response.json()
weather_codes=[]
will_rain = False
time=""
for i in range(0, 13):
code = data["hourly"][i]["weather"][0]["id"]
if code < 700:
will_rain = True
time += f"{i + 1}, "
if will_rain:
client = Client(account_sid, auth_token)
message = client.messages \
.create(
body=f"It's going to rain today at hours : {time} Bring an Umbrella! ☂️",
from_=TWILIO_NUMBER,
to=MOBILE_NUMBER
)
print(message.status)