DEV Community

Trix Cyrus
Trix Cyrus

Posted on

🔁 How to Automate Everyday Tasks with Python – Part 2

Python isn’t just for beginners—it’s a powerhouse for automating both simple and complex workflows. In Part 1, we looked at file handling, web scraping, email automation, Google Sheets, system monitoring, and browser automation.

In Part 2, we explore more advanced automation patterns using APIs, PDFs, screenshots, backups, and schedulers that can level up your day-to-day productivity as a developer, sysadmin, or even a tech hobbyist.


7. Automating API Calls (Data Fetching & Integration)

Python's requests library is perfect for consuming APIs. Let’s automate fetching weather data:

import requests

API_KEY = 'your_api_key_here'
city = 'Delhi'
url = f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_KEY}&units=metric'

response = requests.get(url).json()

print(f"{city} | Temp: {response['main']['temp']}°C | Weather: {response['weather'][0]['description']}")
Enter fullscreen mode Exit fullscreen mode

📌 You can use this with Slack bots, daily notifications, or even display on a local dashboard.


8. Automating PDF Editing and Generation

Use PyPDF2 and fpdf to automate PDF reading, merging, and report generation:

Merging multiple PDFs:

from PyPDF2 import PdfMerger

merger = PdfMerger()
files = ['report1.pdf', 'report2.pdf']

for file in files:
    merger.append(file)

merger.write("merged_report.pdf")
merger.close()
Enter fullscreen mode Exit fullscreen mode

Creating a custom PDF:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
pdf.cell(200, 10, txt="Automated PDF Report", ln=True)
pdf.output("auto_report.pdf")
Enter fullscreen mode Exit fullscreen mode

Great for automated invoices, logs, summaries, etc.


9. Automating Screenshots (UI Monitoring or Documentation)

Using pyautogui:

import pyautogui

screenshot = pyautogui.screenshot()
screenshot.save("desktop_capture.png")
Enter fullscreen mode Exit fullscreen mode

📷 Combine this with schedule to take hourly screenshots or use it to document UI test runs.


10. Automating Backups (Files or Folders)

You can create automated backups using shutil and timestamps:

import shutil
import datetime

src = '/path/to/data'
dst = f'/backup/data_backup_{datetime.datetime.now().strftime("%Y%m%d%H%M%S")}'
shutil.copytree(src, dst)
print(f"Backup created at {dst}")
Enter fullscreen mode Exit fullscreen mode

🗂 Perfect for daily backups of configs, projects, or even databases (dump first).


11. Automating Task Scheduling

Use schedule to automate jobs at intervals:

import schedule
import time

def job():
    print("Running automated task...")

schedule.every().day.at("09:00").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)
Enter fullscreen mode Exit fullscreen mode

You can combine this with:

  • Scrapers
  • Emailers
  • Backups
  • System health checks

12. Automating Notification Systems (Desktop or Pushbullet)

Desktop Notification (Windows/macOS/Linux):

from plyer import notification

notification.notify(
    title='Reminder',
    message='Take a break! Hydrate and stretch.',
    timeout=5
)
Enter fullscreen mode Exit fullscreen mode

Push to Mobile with Pushbullet:

import requests

TOKEN = 'your_access_token'
data = {'type': 'note', 'title': 'Update', 'body': 'Your daily automation report is ready.'}
requests.post('https://api.pushbullet.com/v2/pushes', json=data, headers={'Access-Token': TOKEN})
Enter fullscreen mode Exit fullscreen mode

13. Automating Telegram Bots

Send messages to a Telegram chat using your bot token:

import requests

bot_token = 'YOUR_BOT_TOKEN'
chat_id = 'YOUR_CHAT_ID'
message = 'Automated message from your Python script!'

url = f'https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={message}'
requests.get(url)
Enter fullscreen mode Exit fullscreen mode

🤖 Use it to alert you about server load, new logs, or system failures.


14. Automating YouTube Video Downloads

Use pytube to download videos or audio:

from pytube import YouTube

yt = YouTube('https://www.youtube.com/watch?v=example')
stream = yt.streams.get_highest_resolution()
stream.download(output_path='downloads/')
Enter fullscreen mode Exit fullscreen mode

Ideal for offline storage, batch downloaders, or content archiving.


15. Automating Image Compression

If you're uploading images regularly, automate optimization:

from PIL import Image
import os

for img_file in os.listdir('images'):
    if img_file.endswith('.jpg'):
        img_path = os.path.join('images', img_file)
        img = Image.open(img_path)
        img.save(f"compressed/{img_file}", optimize=True, quality=60)
Enter fullscreen mode Exit fullscreen mode

🖼 Useful for bloggers, content creators, and web developers.


⚡ Final Thoughts

As you’ve seen across both parts of this series, Python is your digital Swiss Army knife for personal productivity, system automation, and smart workflows.

Whether you're automating file systems, web scraping, backups, or pushing notifications, the key takeaway is this:

🔁 If you’ve done it twice manually, you can probably automate it with Python.


📌 What's Next?
In Part 3, we’ll explore:

  • Building GUIs for your automations (with Tkinter/Streamlit)
  • Voice-based automations
  • AI integrations (ChatGPT bots, summarizers)
  • Real-world use cases from the cybersecurity world

💬 Got ideas or want a GitHub repo with all these scripts? Drop a comment or DM. Let’s build it together!


Top comments (0)