Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

REMINER VIA MAIL

import schedule
import smtplib
import requests
from bs4 import BeautifulSoup
  
  
def umbrellaReminder():
    city = "Hyderabad"
      
    # creating url and requests instance
    url = "https://www.google.com/search?q=" + "weather" + city
    html = requests.get(url).content
      
    # getting raw data
    soup = BeautifulSoup(html, 'html.parser')
    temperature = soup.find('div',
                            attrs={'class': 'BNeawe iBp4i AP7Wnd'}).text
    time_sky = soup.find('div', 
                         attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text
      
    # formatting data
    sky = time_sky.split('
')[1]
  
    if sky == "Rainy" or sky == "Rain And Snow" or sky == "Showers" or sky == "Haze" or sky == "Cloudy":
        smtp_object = smtplib.SMTP('smtp.gmail.com', 587)
          
        # start TLS for security
        smtp_object.starttls()
          
        # Authentication
        smtp_object.login("YOUR EMAIL", "PASSWORD")
        subject = "GeeksforGeeks Umbrella Reminder"
        body = f"Take an umbrella before leaving the house.
        Weather condition for today is {sky} and temperature is
        {temperature} in {city}."
        msg = f"Subject:{subject}

{body}

Regards,
GeeksforGeeks".encode(
            'utf-8')
          
        # sending the mail
        smtp_object.sendmail("FROM EMAIL",
                             "TO EMAIL", msg)
          
        # terminating the session
        smtp_object.quit()
        print("Email Sent!")
  
  
# Every day at 06:00AM time umbrellaReminder() is called.
schedule.every().day.at("06:00").do(umbrellaReminder)
  
while True:
    schedule.run_pending()
Comment

PREVIOUS NEXT
Code Example
Python :: python groupby 1d array 
Python :: Access value 
Python :: test a decorator python 
Python :: Start Django Project At http://127.0.0.1:8080/ 
Python :: 198727191002 
Python :: A Simple Class 
Python :: How to run python in command promt 
Python :: gricsearchcv sample_weights 
Python :: csv file python 
Python :: How to Use Sets to Remove Duplicate Items in Other Data Structures 
Python :: pydantic model and ORM model 
Python :: select data frame with categorical datatype in pandas 
Python :: Python Tkinter RadioButton Widget Syntax 
Python :: percent change pandas using log 
Python :: for loop for multiple things 
Python :: if len formula applied to a column python 
Python :: python workbook.add_format in percentage 
Python :: panda3d intervals 
Python :: operator overloading in python 
Python :: flask docker redirect container name 
Python :: qr code scanner on django 
Python :: How to print specific figure in python 
Python :: python using type and name advanced 
Python :: how to filter even or odd model id in django 
Python :: importare un foglio di un file excel in python 
Python :: animal quiz game in python 
Python :: what is a console in pythonanywhere 
Python :: not staments python 
Python :: create loading in pyqt 
Python :: inspect rows in dictionary pthon 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =