From 3c5c6aa248de11e9b8d48774d0e36a1da19d5ab4 Mon Sep 17 00:00:00 2001 From: Shubhrima Jana Date: Fri, 30 Apr 2021 08:50:13 +0530 Subject: [PATCH 1/9] Added Rain Alert Mail Sender --- Rain Alert Mail Sender/README.md | 9 ++++++ Rain Alert Mail Sender/main.py | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Rain Alert Mail Sender/README.md create mode 100644 Rain Alert Mail Sender/main.py diff --git a/Rain Alert Mail Sender/README.md b/Rain Alert Mail Sender/README.md new file mode 100644 index 0000000000..5d0f800b93 --- /dev/null +++ b/Rain Alert Mail Sender/README.md @@ -0,0 +1,9 @@ +# Rain Alert Mail Sender + +

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

+ +

Libraries used : requests, smtp, time, datetime

+ + +# Author(s) +Shubhrima Jana \ No newline at end of file diff --git a/Rain Alert Mail Sender/main.py b/Rain Alert Mail Sender/main.py new file mode 100644 index 0000000000..c4eb9bd8ae --- /dev/null +++ b/Rain Alert Mail Sender/main.py @@ -0,0 +1,48 @@ +import requests +from smtplib import SMTP + +#turn off certain security criteria in sender mail address +MY_MAIL= ENTER_YOUR_MAIL +MY_PASSWORD= ENTER_YOUR_PASSWORD +RECIEVER_MAIL = RECIEVER_MAIL +#get latitude longitude from "https://www.latlong.net/" +LAT = 22.572645 +LONG = 88.363892 + +API_KEY = API + +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() +print(data) + +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): + 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=f"Subject: Rain Rain \n\nIt's going to rain today. Bring Umbrella ") + print('Mail Sent') +else: + 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='shubhrijana@gmail.com', + msg=f"Subject: Sunny Day\n\nMay be a sunny day. Carry sunglasses. ") + print('Mail Sent') + + + From 2853b8d9004bf3260a3fb595fe7dd1a6f4751a0b Mon Sep 17 00:00:00 2001 From: Shubhrima Jana <68013183+Shubhrima@users.noreply.github.com> Date: Fri, 30 Apr 2021 09:00:04 +0530 Subject: [PATCH 2/9] Update README.md --- Rain Alert Mail Sender/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Rain Alert Mail Sender/README.md b/Rain Alert Mail Sender/README.md index 5d0f800b93..e22de0df89 100644 --- a/Rain Alert Mail Sender/README.md +++ b/Rain Alert Mail Sender/README.md @@ -4,6 +4,8 @@

Libraries used : requests, smtp, time, datetime

+ + # Author(s) -Shubhrima Jana \ No newline at end of file +Shubhrima Jana From 65fcb01150a686d57b2b7efba3111edb3ecf343f Mon Sep 17 00:00:00 2001 From: Shubhrima Jana <68013183+Shubhrima@users.noreply.github.com> Date: Sat, 1 May 2021 10:44:03 +0530 Subject: [PATCH 3/9] made necessary changes --- Rain Alert Mail Sender/main.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Rain Alert Mail Sender/main.py b/Rain Alert Mail Sender/main.py index c4eb9bd8ae..99115948a2 100644 --- a/Rain Alert Mail Sender/main.py +++ b/Rain Alert Mail Sender/main.py @@ -2,15 +2,23 @@ from smtplib import SMTP #turn off certain security criteria in sender mail address -MY_MAIL= ENTER_YOUR_MAIL -MY_PASSWORD= ENTER_YOUR_PASSWORD -RECIEVER_MAIL = RECIEVER_MAIL -#get latitude longitude from "https://www.latlong.net/" -LAT = 22.572645 -LONG = 88.363892 +MY_MAIL= input('Enter your mail id: ') +MY_PASSWORD= input('Enter password: ') +RECIEVER_MAIL = input('Send mail to (mail id): ') +CITY = input('Enter your City: ') -API_KEY = API +API_KEY = input('Type in API from OpenWeather: ') +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, @@ -20,7 +28,6 @@ api = requests.get(url="http://api.openweathermap.org/data/2.5/onecall",params=PARAMETER) data = api.json() -print(data) bring_umbrella = False @@ -43,6 +50,3 @@ connection.sendmail(from_addr=MY_MAIL, to_addrs='shubhrijana@gmail.com', msg=f"Subject: Sunny Day\n\nMay be a sunny day. Carry sunglasses. ") print('Mail Sent') - - - From 188acc3f7fc6ca929b68c58e627c567d77b62f20 Mon Sep 17 00:00:00 2001 From: Shubhrima Jana <68013183+Shubhrima@users.noreply.github.com> Date: Sun, 2 May 2021 12:17:44 +0530 Subject: [PATCH 4/9] Update main.py --- Rain Alert Mail Sender/main.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Rain Alert Mail Sender/main.py b/Rain Alert Mail Sender/main.py index 99115948a2..64071b44e0 100644 --- a/Rain Alert Mail Sender/main.py +++ b/Rain Alert Mail Sender/main.py @@ -1,20 +1,21 @@ import requests from smtplib import SMTP +import time #turn off certain security criteria in sender mail address MY_MAIL= input('Enter your mail id: ') MY_PASSWORD= input('Enter password: ') RECIEVER_MAIL = input('Send mail to (mail id): ') +#get latitude longitude from "https://www.latlong.net/" CITY = input('Enter your City: ') -API_KEY = input('Type in API from OpenWeather: ') +API_KEY = input('Type in API key from OpenWeather: ') 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'] @@ -37,16 +38,14 @@ bring_umbrella = True if (bring_umbrella == True): - 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=f"Subject: Rain Rain \n\nIt's going to rain today. Bring Umbrella ") - print('Mail Sent') + MESSAGE=f"Subject: Rain Rain \n\nIt's going to rain today. Bring Umbrella " + else: - 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='shubhrijana@gmail.com', - msg=f"Subject: Sunny Day\n\nMay be a sunny day. Carry sunglasses. ") - print('Mail Sent') + 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') From 2f7fd4446427c6de97c4b0e4659711a6ff9fa7e0 Mon Sep 17 00:00:00 2001 From: Shubhrima Jana <68013183+Shubhrima@users.noreply.github.com> Date: Sun, 2 May 2021 12:18:45 +0530 Subject: [PATCH 5/9] Update main.py --- Rain Alert Mail Sender/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Rain Alert Mail Sender/main.py b/Rain Alert Mail Sender/main.py index 64071b44e0..3445899f71 100644 --- a/Rain Alert Mail Sender/main.py +++ b/Rain Alert Mail Sender/main.py @@ -1,6 +1,5 @@ import requests from smtplib import SMTP -import time #turn off certain security criteria in sender mail address MY_MAIL= input('Enter your mail id: ') From 580c9fcb8336d800ee37b4b36935a3349b20446e Mon Sep 17 00:00:00 2001 From: Shubhrima Jana <68013183+Shubhrima@users.noreply.github.com> Date: Tue, 4 May 2021 09:08:19 +0530 Subject: [PATCH 6/9] Update main.py --- Rain Alert Mail Sender/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Rain Alert Mail Sender/main.py b/Rain Alert Mail Sender/main.py index 3445899f71..bd8d3465c9 100644 --- a/Rain Alert Mail Sender/main.py +++ b/Rain Alert Mail Sender/main.py @@ -5,7 +5,6 @@ MY_MAIL= input('Enter your mail id: ') MY_PASSWORD= input('Enter password: ') RECIEVER_MAIL = input('Send mail to (mail id): ') -#get latitude longitude from "https://www.latlong.net/" CITY = input('Enter your City: ') API_KEY = input('Type in API key from OpenWeather: ') From afaf8cfcbccb7a75568e87988555db44e599c652 Mon Sep 17 00:00:00 2001 From: Shubhrima Jana <68013183+Shubhrima@users.noreply.github.com> Date: Tue, 4 May 2021 09:26:15 +0530 Subject: [PATCH 7/9] Update main.py --- Rain Alert Mail Sender/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Rain Alert Mail Sender/main.py b/Rain Alert Mail Sender/main.py index bd8d3465c9..94cdb5ec85 100644 --- a/Rain Alert Mail Sender/main.py +++ b/Rain Alert Mail Sender/main.py @@ -1,7 +1,11 @@ import requests from smtplib import SMTP -#turn off certain security criteria in sender mail address +def function(): + """Go to Manage your Google (or any other sender 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= input('Enter your mail id: ') MY_PASSWORD= input('Enter password: ') RECIEVER_MAIL = input('Send mail to (mail id): ') From 3df81f907f4a570b6633a77a4bb969676f792bf0 Mon Sep 17 00:00:00 2001 From: Shubhrima Jana <68013183+Shubhrima@users.noreply.github.com> Date: Tue, 4 May 2021 20:18:46 +0530 Subject: [PATCH 8/9] Update main.py --- Rain Alert Mail Sender/main.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Rain Alert Mail Sender/main.py b/Rain Alert Mail Sender/main.py index 94cdb5ec85..4f19152e72 100644 --- a/Rain Alert Mail Sender/main.py +++ b/Rain Alert Mail Sender/main.py @@ -1,17 +1,21 @@ import requests from smtplib import SMTP +import os +from dotenv import load_dotenv + +load_dotenv() def function(): - """Go to Manage your Google (or any other sender 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. + """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= input('Enter your mail id: ') -MY_PASSWORD= input('Enter password: ') +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 = input('Type in API key from OpenWeather: ') +API_KEY = os.getenv('API') API_END_POINT ='https://nominatim.openstreetmap.org/search.php' PARAMETER_LOCATION ={ @@ -29,7 +33,6 @@ def function(): "exclude" : "current,minutely,daily", } api = requests.get(url="http://api.openweathermap.org/data/2.5/onecall",params=PARAMETER) - data = api.json() bring_umbrella = False From 1807d9b6ec12417ded18c6027d4d2d355af13594 Mon Sep 17 00:00:00 2001 From: Shubhrima Jana Date: Fri, 14 May 2021 08:48:14 +0530 Subject: [PATCH 9/9] Added requirements --- Rain Alert Mail Sender/requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Rain Alert Mail Sender/requirements.txt diff --git a/Rain Alert Mail Sender/requirements.txt b/Rain Alert Mail Sender/requirements.txt new file mode 100644 index 0000000000..b4f6d53390 --- /dev/null +++ b/Rain Alert Mail Sender/requirements.txt @@ -0,0 +1,2 @@ +requests==2.25.1 +dotenv==0.05 \ No newline at end of file