File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ import requests
2
+ import os
3
+ from twilio .rest import Client
4
+
5
+ # Add twilio number
6
+ number = ''
7
+
8
+ OWM_Endpoint = "https://api.openweathermap.org/data/2.5/onecall"
9
+ api_key = os .environ .get ("OWM_key" )
10
+ # Add your id
11
+ account_sid = ""
12
+ auth_token = os .environ .get ("twillo_auth_token" )
13
+
14
+ weather_params = {
15
+ "lat" : 31.1048 ,
16
+ "exclude" : "current,minutely,daily" ,
17
+ "lon" : 77.1734 ,
18
+ "appid" : api_key
19
+ }
20
+
21
+ will_rain = False
22
+
23
+ response = requests .get (OWM_Endpoint , params = weather_params )
24
+ weather_data = response .json ()
25
+ weather_slice = weather_data ['hourly' ][:12 ]
26
+ for hourly_data in weather_slice :
27
+ condition_code = hourly_data ['weather' ][0 ]['id' ]
28
+ if int (condition_code ) < 700 :
29
+ will_rain = True
30
+
31
+ if will_rain :
32
+ client = Client (account_sid , auth_token )
33
+ message = client .messages .create (
34
+ body = "It's going to rain today. Take your umbrella " ,
35
+ from_ = number ,
36
+ #add number you want to send the message to
37
+ to = ''
38
+ )
39
+ print (message .status )
You can’t perform that action at this time.
0 commit comments