Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 44a71e7

Browse files
Added Rain Alert Mail Sender (avinashkranjan#997)
1 parent 123dab9 commit 44a71e7

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

‎Rain Alert Mail Sender/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Rain Alert Mail Sender
2+
3+
<p> An application that checks the weather condition for the next 12 hours and sends a message to the registered mail address number as to whether one should carry a sunglass (if it is sunny) , or an umbrella (if it rains).</p>
4+
5+
<p>Libraries used : requests, smtp, time, datetime</p>
6+
7+
<img src="https://user-images.githubusercontent.com/68013183/116644886-30901380-a992-11eb-8acd-cf0395a433e4.png" width="550">
8+
9+
10+
# Author(s)
11+
Shubhrima Jana

‎Rain Alert Mail Sender/main.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import requests
2+
from smtplib import SMTP
3+
import os
4+
from dotenv import load_dotenv
5+
6+
load_dotenv()
7+
8+
def function():
9+
"""Go to Manage your Google(or any mail) account, and then headover to Security.\nTurn OFF the options 'Two Step Verification' and 'Use your phone to sign in' in the Signing in to Google section.\nTurn ON the Less secure apps section.
10+
"""
11+
return 0
12+
print(function.__doc__)
13+
MY_MAIL= os.getenv('MAIL')
14+
MY_PASSWORD= os.getenv('PASSWORD')
15+
RECIEVER_MAIL = input('Send mail to (mail id): ')
16+
CITY = input('Enter your City: ')
17+
18+
API_KEY = os.getenv('API')
19+
20+
API_END_POINT ='https://nominatim.openstreetmap.org/search.php'
21+
PARAMETER_LOCATION ={
22+
'city' : CITY,
23+
'format': 'json',
24+
}
25+
response_location = requests.get(url = API_END_POINT, params=PARAMETER_LOCATION)
26+
data_location = response_location .json()
27+
LAT = data_location [0]['lat']
28+
LONG = data_location [0]['lon']
29+
PARAMETER= {
30+
"lat": LAT,
31+
"lon": LONG,
32+
"appid" : API_KEY,
33+
"exclude" : "current,minutely,daily",
34+
}
35+
api = requests.get(url="http://api.openweathermap.org/data/2.5/onecall",params=PARAMETER)
36+
data = api.json()
37+
38+
bring_umbrella = False
39+
40+
for i in range(0,12):
41+
hourly_condition = data['hourly'][i]['weather'][0]['id']
42+
if(hourly_condition<700):
43+
bring_umbrella = True
44+
45+
if (bring_umbrella == True):
46+
MESSAGE=f"Subject: Rain Rain \n\nIt's going to rain today. Bring Umbrella "
47+
48+
else:
49+
MESSAGE = f"Subject: Sunny Day\n\nMay be a sunny day. Carry sunglasses. "
50+
51+
with SMTP("smtp.gmail.com") as connection:
52+
connection.starttls()
53+
connection.login(user=MY_MAIL, password=MY_PASSWORD)
54+
connection.sendmail(from_addr=MY_MAIL, to_addrs=RECIEVER_MAIL,
55+
msg=MESSAGE)
56+
print('Mail Sent')

‎Rain Alert Mail Sender/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests==2.25.1
2+
dotenv==0.05

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /