Skip to content

Commit 3ccc5cf

Browse files
author
Lenar Gasimov
committed
feat: added complete day 35
Learnt about env variables and built a rain alert application using open weather map API and deployed it in http://pythonanywhere.com to get daily SMS notifications using Twilio API on weather in my current location.
1 parent f47b932 commit 3ccc5cf

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ I'll be using this repo as a way for myself to access them as, if and when I nee
5050
- [Day 32](day32): Send Email (smtplib) & Manage Dates (datetime): The Automated Birthday Wisher
5151
- [Day 33](day33): API Endpoints and API Parameters - ISS Overhead Notifier
5252
- [Day 34](day34): API Practice - Creating a GUI Quiz App
53-
53+
- [Day 35](day35): Keys, Authentication & Environment Variables: Send SMS
5454

5555
<p align="center">
5656
<img width="360" src="cat.gif" alt="profile" />

day35/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Day 35
2+
3+
Learnt about env variables and built a rain alert application using open weather map API and deployed it in http://pythonanywhere.com to get daily SMS notifications using Twilio API on weather in my current location.
4+
5+
## Rain Notification
6+
7+
![rain](rain.png)

day35/main.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import requests
2+
import os
3+
from twilio.rest import Client
4+
from twilio.http.http_client import TwilioHttpClient
5+
6+
OWM_Endpoint = "https://api.openweathermap.org/data/2.5/onecall"
7+
api_key = "8f14ac1ce7426fef035aa2a985c43017"
8+
account_sid = "******************"
9+
auth_token = "******************"
10+
11+
weather_params = {
12+
"lat": 55.740280,
13+
"lon": 52.398109,
14+
"appid": api_key,
15+
"exclude": "current, minutely, daily"
16+
}
17+
18+
response = requests.get(OWM_Endpoint, params=weather_params)
19+
response.raise_for_status()
20+
weather_data = response.json()
21+
weather_slice = weather_data["hourly"][:12]
22+
23+
will_rain = False
24+
25+
for hour_data in weather_slice:
26+
condition_code = hour_data["weather"][0]["id"]
27+
if int(condition_code) < 700:
28+
will_rain = True
29+
30+
if will_rain:
31+
proxy_client = TwilioHttpClient()
32+
proxy_client.session.proxies = {'https': os.environ['https_proxy']}
33+
34+
client = Client(account_sid, auth_token, http_client=proxy_client)
35+
message = client.messages \
36+
.create(
37+
body="It's going to rain today. Remember to bring an ☔️",
38+
from_="+*********",
39+
to="+*********"
40+
)
41+
print(message.status)

day35/rain.PNG

99 KB
Loading

0 commit comments

Comments
 (0)