Skip to content
This repository was archived by the owner on Dec 20, 2022. It is now read-only.

Commit 9924551

Browse files
authored
Merge pull request larymak#221 from VinayEdula/main
Automation - Umbrella Reminder
2 parents b59be62 + 9957298 commit 9924551

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Umbrella Reminder
2+
3+
## Description
4+
This snippet of code will Scrape weather data using Python to get umbrella reminder on email
5+
6+
## Requirements
7+
8+
`$ pip install bs4`
9+
10+
`$ pip install requests `
11+
12+
`$ pip install smtplib`
13+
14+
`$ pip install schedule `
15+
16+
17+
18+
## Steps To Execution
19+
- First of all you need to Enable Less Secure app access from your sending email account. [(Click Here for reference !!)](https://youtu.be/Ee7PDsbfOUI)
20+
- Fork this repo and navigate to Umbrella-Reminder folder
21+
- Open code.py in any text/code editor
22+
- Write necessary modification in code like your time ,city, mail-id , password ...
23+
- Run this code.py `$ python code.py`
24+
25+
Note: When you execute this program it will throw you a smtplib.SMTPAuthenticationError and also sends you a Critical Security alert to your email because,
26+
In a nutshell, Google is not allowing you to log in via smtplib because it has flagged this sort of login as “less secure”, so what you have to do is go to
27+
this link while you’re logged in to your google account, and allow the access:
28+

AUTOMATION/Umbrella Reminder/code.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import schedule
2+
import smtplib
3+
import requests
4+
from bs4 import BeautifulSoup
5+
6+
7+
def umbrellaReminder():
8+
city = "Hyderabad"
9+
10+
# creating url and requests instance
11+
url = "https://www.google.com/search?q=" + "weather" + city
12+
html = requests.get(url).content
13+
14+
# getting raw data
15+
soup = BeautifulSoup(html, 'html.parser')
16+
temperature = soup.find('div',
17+
attrs={'class': 'BNeawe iBp4i AP7Wnd'}).text
18+
time_sky = soup.find('div',
19+
attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text
20+
21+
# formatting data
22+
sky = time_sky.split('\n')[1]
23+
24+
if sky == "Rainy" or sky == "Rain And Snow" or sky == "Showers" or sky == "Haze" or sky == "Cloudy":
25+
smtp_object = smtplib.SMTP('smtp.gmail.com', 587)
26+
27+
# start TLS for security
28+
smtp_object.starttls()
29+
30+
# Authentication
31+
smtp_object.login("YOUR EMAIL", "PASSWORD")
32+
subject = "GeeksforGeeks Umbrella Reminder"
33+
body = f"Take an umbrella before leaving the house.\
34+
Weather condition for today is {sky} and temperature is\
35+
{temperature} in {city}."
36+
msg = f"Subject:{subject}\n\n{body}\n\nRegards,\nGeeksforGeeks".encode(
37+
'utf-8')
38+
39+
# sending the mail
40+
smtp_object.sendmail("FROM EMAIL",
41+
"TO EMAIL", msg)
42+
43+
# terminating the session
44+
smtp_object.quit()
45+
print("Email Sent!")
46+
47+
48+
# Every day at 06:00AM time umbrellaReminder() is called.
49+
schedule.every().day.at("06:00").do(umbrellaReminder)
50+
51+
while True:
52+
schedule.run_pending()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is for testing purpose

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ The contribution guidelines are as per the guide [HERE](https://github.com/larym
109109
| 61 | [PyQuiz](https://github.com/larymak/Python-project-Scripts/tree/main/GUI/PyQuiz) | [Eduardo C.](https://github.com/ehcelino)
110110
| 62 | [Dates](https://github.com/larymak/Python-project-Scripts/tree/main/GUI/Dates) | [Eduardo C.](https://github.com/ehcelino)
111111
| 63 | [QtQuiz](https://github.com/larymak/Python-project-Scripts/tree/main/GUI/QtQuiz) | [Eduardo C.](https://github.com/ehcelino)
112+
| 64 | [Umbrella Reminder](https://github.com/larymak/Python-project-Scripts/tree/main/AUTOMATION/Umbrella%20Reminder) | [Edula Vinay Kumar Reddy](https://github.com/vinayedula)

0 commit comments

Comments
 (0)