Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Rain Alert Mail Sender/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Rain Alert Mail Sender

<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>

<p>Libraries used : requests, smtp, time, datetime</p>

<img src="https://user-images.githubusercontent.com/68013183/116644886-30901380-a992-11eb-8acd-cf0395a433e4.png" width="550">


# Author(s)
Shubhrima Jana
56 changes: 56 additions & 0 deletions Rain Alert Mail Sender/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import requests
from smtplib import SMTP
import os
from dotenv import load_dotenv

load_dotenv()

def function():
"""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.
"""
return 0
print(function.__doc__)
MY_MAIL= os.getenv('MAIL')
MY_PASSWORD= os.getenv('PASSWORD')
RECIEVER_MAIL = input('Send mail to (mail id): ')
CITY = input('Enter your City: ')

API_KEY = os.getenv('API')

API_END_POINT ='https://nominatim.openstreetmap.org/search.php'
PARAMETER_LOCATION ={
'city' : CITY,
'format': 'json',
}
response_location = requests.get(url = API_END_POINT, params=PARAMETER_LOCATION)
data_location = response_location .json()
LAT = data_location [0]['lat']
LONG = data_location [0]['lon']
PARAMETER= {
"lat": LAT,
"lon": LONG,
"appid" : API_KEY,
"exclude" : "current,minutely,daily",
}
api = requests.get(url="http://api.openweathermap.org/data/2.5/onecall",params=PARAMETER)
data = api.json()

bring_umbrella = False

for i in range(0,12):
hourly_condition = data['hourly'][i]['weather'][0]['id']
if(hourly_condition<700):
bring_umbrella = True

if (bring_umbrella == True):
MESSAGE=f"Subject: Rain Rain \n\nIt's going to rain today. Bring Umbrella "

else:
MESSAGE = f"Subject: Sunny Day\n\nMay be a sunny day. Carry sunglasses. "

with SMTP("smtp.gmail.com") as connection:
connection.starttls()
connection.login(user=MY_MAIL, password=MY_PASSWORD)
connection.sendmail(from_addr=MY_MAIL, to_addrs=RECIEVER_MAIL,
msg=MESSAGE)
print('Mail Sent')
2 changes: 2 additions & 0 deletions Rain Alert Mail Sender/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests==2.25.1
dotenv==0.05