Member-only story
20 Python scripts to automate common daily tasks
4 min readNov 11, 2024
Here are 20 Python scripts to automate common daily tasks, with explanations and examples for each:
1. Email Notifications
Automate sending daily email updates.
import smtplib
from email.message import EmailMessage
def send_email(subject, body, to_email):
msg = EmailMessage()
msg.set_content(body)
msg['Subject'] = subject
msg['From'] = 'youremail@example.com'
msg['To'] = to_email
with smtplib.SMTP('smtp.example.com', 587) as smtp:
smtp.starttls()
smtp.login('youremail@example.com', 'password')
smtp.send_message(msg)
send_email('Daily Update', 'Your daily update goes here.', 'recipient@example.com')
2. Web Scraping for News Headlines
Automatically fetches the latest news headlines from a website.
import requests
from bs4 import BeautifulSoup
def get_news():
url = 'https://news.ycombinator.com/'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
headlines = [item.text for item in soup.select('.storylink')[:5]]
return headlines
print(get_news())