-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay35.py
More file actions
40 lines (34 loc) · 1.2 KB
/
Day35.py
File metadata and controls
40 lines (34 loc) · 1.2 KB
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
import smtplib
import requests
my_email = "ask@gmail.com"
my_password = "************"
take_an_umbrella_email = ("Subject:It's going to rain today!\n\n"
"Hey, its going to be raining today. Take an umbrella with you. :)")
will_rain = False
USER_LATITUDE = 12.971599
USER_LONGITUDE = 77.594566
# Can be obtained here: https://openweathermap.org/api
API_KEY = "************"
weather_data_parameters = {
"lat": USER_LATITUDE,
"lon": USER_LONGITUDE,
"appid": API_KEY,
"units": "metric",
"cnt": 4
}
print("Day 35 - 100 Days of Code.")
print("Welcome to Rain Alert Email.")
weather_data = requests.get("https://api.openweathermap.org/data/2.5/forecast", params=weather_data_parameters)
weather_data.raise_for_status()
weather_data = weather_data.json()["list"]
weather_condition = []
for iterator in range(4):
if weather_data[iterator]["weather"][0]["id"] in range(200, 540):
will_rain = True
else:
pass
if will_rain:
with smtplib.SMTP("SMTP.gmail.com") as connection:
connection.starttls()
connection.login(user=my_email, password=my_password)
connection.sendmail(from_addr=my_email, to_addrs=my_email, msg=take_an_umbrella_email)