- read

5 Python Automation Scripts I Use Every Day

Graham Zemel 91

TL;DR- A quick list of the best Python scripts I use on a daily basis, plus some possible modifications that could be made for other functionalities.

Introduction

Python is a powerful programming language that can be used to automate a variety of tasks. Whether you’re developing a small project or a large enterprise app, Python can help save time and streamline your workflow.

Python is a great language because of its incredibly simple syntax. What a decent programmer can code in 10 lines of Python would take them 20 lines in a language like Javascript or C++. Here’s an example with a simple web request →

import requests 
r = requests.get(“https://www.python.org")
print(r.status_code)
print(r.text)

In comparison, here’s the Javascript code that does the exact same thing

fetch(“https://www.python.org")
.then(res => {
if(res.ok) {
return res.text();
} else {
throw new Error(“HTTP error, status = “ + res.status);
}
})
.then(text => {
console.log(text);
})
.catch(error => {
console.log(error);
});

As you can see, the Python code is far easier to digest than the Javascript code, and this makes it ideal for automating repetitive tasks for things like web scraping, data collection, or translation. Here are five of my favorite repetitive tasks that I automate with Python

A URL Shortener →

import pyshorteners

s = pyshorteners.Shortener(api_key="YOUR_KEY")

long_url = input("Enter the URL to shorten: ")

short_url = s.bitly.short(long_url)

print("The shortened URL is: " + short_url)

The Pyshorteners library is one of my favorites when it comes to URL shortening, which can be used for all sorts of projects. You’ll need an API key for most link shorteners, but they’re usually free unless you anticipate hundreds of thousands of requests. I’ve found that APIs like Bit.ly, Adf.ly, and Tinyurl are great for things like SaaS apps and Telegram bots.

Creating Fake Information →

import pandas as pd
from faker import Faker

# Create object
fake = Faker()

# Generate data
fake.name()
fake.text()
fake.address()
fake.email()…