-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (59 loc) · 2.08 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import requests
from twilio.rest import Client
import os
account_sid = 'AC6ce642cdb9e2cf3bd2d3fd03564dcf9a'
auth_token = os.environ.get("AUTH_TOKEN")
MY_LAT = 34.052235
MY_LNG = -118.243683
exclude_data = "current,minutely,daily"
api_key = os.environ.get("API_KEY")
# Let's just write the OWM address here to make it even much clear:
# And down below are all working free:
# OWM_Endpoint = "https://api.openweathermap.org/data/2.5/weather" # current weather
OWM_Endpoint = "https://api.openweathermap.org/data/2.8/onecall"
# OWM_Endpoint = "https://api.openweathermap.org/data/2.5/forecast"
parameters = {
"lat": MY_LAT,
"lon": MY_LNG,
"appid": api_key,
"exclude": exclude_data # We want to only fetch what we need, exclude else.
}
response = requests.get(OWM_Endpoint,
params=parameters)
# Testify if our request is okay:
# print(response.status_code)
response.raise_for_status()
data = response.json()
# print(data)
# print(data["hourly"][:13])
within_12hours = data["hourly"][:12]
will_rain = False
for item in within_12hours:
# What I wrote:
# print(item["weather"])
# for i in item["weather"]:
# print(i["id"])
# if i["id"] < 700:
# print("it will rain") # This is where need to put "Sending Out SMS" coding.
# if item["weather"]["id"] < 700:
# print(f"It will rain! {item['weather']['id']}")
# print(item["weather"]["id"])
# What dr.Angela wrote:
# print(item["weather"][0]["id"])
condition_code = item["weather"][0]["id"]
if condition_code < 700:
# print("it will rain") # instead printing every < 700 would rain:
will_rain = True # Let's write it as only once, so we will bring umbrella next 12 hrs.
if will_rain:
# print("Bring an umbrella")
# Using Twilio:
client = Client(account_sid, auth_token)
message = client.messages.create(
from_='+18444821071',
body='It gonna rain today! Bring an umbrella :) 🙂☔️🌧',
to='+16268736132'
)
print(message.status)
print(message.sid)
# commit test
# test .env file