Email Robotization / Web Scrubber

Click Me


18 Madly Strong Python Motorization Items I Use Ordinary

In the domain of programming, robotization is a staggering resource that can save time and abatement drawn-out tasks. This chronicle outlines 18 Python scripts that I see as incredibly significant in my ordinary work process. These items cover various tasks, from record the board to web scratching, and can help with streamlining your cycles and further foster productivity.

1. Archive Organizer

A substance that normally organizes records in a foreordained list into subfolders considering report types.

import os

import shutil

def organize_files(directory):

    for filename in os.listdir(directory):

        if os.path.isfile(os.path.join(directory, filename)):

            file_extension = filename.split('.')[-1]

            folder_path = os.path.join(directory, file_extension)

            if not os.path.exists(folder_path):

                os.makedirs(folder_path)

            shutil.move(os.path.join(directory, filename), os.path.join(folder_path, filename))

organize_files('/way/to/inventory')

👇

https://share.temu.com/oGauvPRQylA 

2. Web Scrubber

An essential web scrubber that isolates data from a website page and saves it to a CSV record.

import requests

from bs4 import BeautifulSoup

import csv

def scrape_website(url):

    response = requests.get(url)

    soup = BeautifulSoup(response.text, 'html.parser')

    data = []

    for thing in soup.find_all('h2'):

        data.append(item.text)

    with open('output.csv', 'w', newline='') as record:

        writer = csv.writer(file)

        writer.writerows(data)

scrape_website('https://example.com')

3. Email Robotization

A substance that sends robotized messages using SMTP.

import smtplib

from email.mime.text import MIMEText

def send_email(subject, body, to_email):

    msg = MIMEText(body)

    msg['Subject'] = subject

    msg['From'] = 'your_email@example.com'

    msg['To'] = to_email

    with smtplib.SMTP('smtp.example.com', 587) as server:

        server.starttls()

        server.login('your_email@example.com', 'your_password')

        server.send_message(msg)

send_email('Test Subject', 'This is a test email.', 'recipient@example.com')

4. Data Support

A substance that makes fortifications of huge records or lists.

import shutil

import os

def backup_files(source, objective):

    if not os.path.exists(destination):

        os.makedirs(destination)

    shutil.copytree(source, objective)

backup_files('/way/to/source', '/way/to/support')

5. PDF Union

A substance that mixes different PDF records into a singular PDF.

from PyPDF2 import PdfMerger

def merge_pdfs(pdf_list, yield):

    union = PdfMerger()

    for pdf in pdf_list:

        merger.append(pdf)

    merger.write(output)

    merger.close()

merge_pdfs(['file1.pdf', 'file2.pdf'], 'merged.pdf')

6. Picture Resizer

A substance that resizes pictures in a predefined vault.

from PIL import Picture

import os

def resize_images(directory, size):

    for filename in os.listdir(directory):

        if filename.endswith('.jpg') or filename.endswith('.png'):

            img = Image.open(os.path.join(directory, filename))

            img = img.resize(size)

            img.save(os.path.join(directory, filename))

resize_images('/way/to/pictures', (800, 600))

7. Task Scheduler

A clear endeavor scheduler that runs a foreordained capacity at ordinary ranges.

import time

def scheduled_task():

    print("Task is running...")

while Substantial:

    scheduled_task()

    time.sleep(3600) # Runs reliably

8. Environment Fetcher

A substance that gets and shows the continuous environment for a predefined region.

import requests

def get_weather(city):

    api_key = 'your_api_key'

    url = f'http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}'

    response = requests.get(url)

    data = response.json()

    print(f"Weather in {city}: {data['weather'][0]['description']}")

get_weather('London')

9. Cash Converter

A substance that changes over cash using a Programming connection point.

import requests

def convert_currency(amount, from_currency, to_currency):

    url = f'https://api.exchangerate-api.com/v4/latest/{from_currency}'

    response = requests.get(url)

    rates = response.json()['rates']

    return aggregate * rates[to_currency]

print(convert_currency(100, 'USD', 'EUR'))

10. Markdown to HTML Converter

A substance that changes over Markdown records to HTML.

import markdown

def convert_markdown_to_html(markdown_file):

    with open(markdown_file, 'r') as archive:

        text = file.read()

    html = markdown.markdown(text)

    with open('output.html', 'w') as record:

        file.write(html)

convert_markdown_to_html('example.md')

11. URL Shortener

A substance that truncates URLs using a Programming connection point.

import requests

def shorten_url(url):

    api_url = 'https://api.shrtco.de/v2/abridge'

    response = requests.post(api_url, data={'url': url})

    return response.json()['result']['short_link']

print(shorten_url('https://example.com'))

12. Text Record Analyzer

A substance that inspects a text report and gives word count and repeat.

from groupings import Counter

def analyze_text_file(file_path):

    with open(file_path, 'r') as archive:

        text = file.read()

    words = text.split()

    word_count = len(words)

    word_frequency = Counter(words)

    print(f'Word Count: {word_count}')

    print(f'Word Repeat: {word_frequency}')

analyze_text_file('example.txt')

13. Git Computerization

A substance that mechanizes typical Git orders.

import os

def git_push():

    os.system('git add .')

    os.system('git commit - m "Electronic commit"')

    os.system('git push')

git_push()

👇

https://share.temu.com/oGauvPRQylA 

14. Slack Notifier

A substance that sends alerts to an Elbowroom channel.

import requests

def send_slack_message(message):

    webhook_url = 'https://hooks.slack.com/organizations/your/webhook/url'

    requests.post(webhook_url, json={'text': message})

send_slack_message('Hello, Slack!')

15. CSV to JSON Converter

A substance that changes over CSV records to JSON plan.

import csv

import json

def csv_to_json(csv_file, json_file):

    with open(csv_file, 'r') as archive:

        peruser = csv.DictReader(file)

        data = [row for segment in reader]

    with open(json_file, 'w') as record:

        json.dump(data, record)

csv_to_json('input.csv', 'output.json')

16. System Screen

A substance that screens system resources and logs them.

import psutil

import time

def log_system_usage():

    while Substantial:

        focal processor = psutil.cpu_percent()

        memory = psutil.virtual_memory().percent

        print(f'CPU: {cpu}%, Memory: {memory}%')

        time.sleep(60)

log_system_usage()

17. Update Application

A fundamental update application that sends alerts.

import time

def reminder(message, delay):

    time.sleep(delay)

    print(f'Reminder: {message}')

reminder('Take a break!', 3600) # Update following an hour

18. Sporadic Mystery key Generator

A substance that creates a sporadic mystery key.

import sporadic

import string

def generate_password(length):

    characters = string.ascii_letters + string.digits + string.punctuation

    secret word = ''.join(random.choice(characters) for I in range(length))

    bring secret word back

print(generate_password(12))

End:

These Python items can basically further develop your proficiency by means of automating customary endeavors. Feel free to change them according to your necessities and direction them into your everyday ordinary practice!

Comments