☰
Current Page
Main Menu
Home
Home
Editing 5 Killer Automation Scripts in Python — Part 2
Edit
Preview
H1
H2
H3
default
Set your preferred keybinding
default
vim
emacs
markdown
Set this page's format to
AsciiDoc
Creole
Markdown
MediaWiki
Org-mode
Plain Text
RDoc
Textile
Rendering unavailable for
BibTeX
Pod
reStructuredText
Help 1
Help 1
Help 1
Help 2
Help 3
Help 4
Help 5
Help 6
Help 7
Help 8
Autosaved text is available. Click the button to restore it.
Restore Text
https://medium.com/codex/5-killer-automation-scripts-in-python-part-2-5b5a8995eef8 # 5 Killer Automation Scripts in Python — Part-2 | by Ishaan Gupta | CodeX | Medium Here are some awesome automation scripts that you can use in your Python projects. ----------------------------------------------------------------------------------  [Ishaan Gupta](https://medium.com/@ishaangupta1201)  [CodeX](https://medium.com/codex) Credits — [LINK](https://www.freepik.com/free-photo/impressed-blond-female-ceo-manager-checking-out-something-amazing-gasping-fascinated-saying-wow-holding-hands-cheeks-staring-front-white-wall_19294243.htm#query=wow&position=5&from_view=search) **This is the second part of this article —** [**https://medium.com/codex/5-killer-automation-scripts-in-python-42c273fc37c4**](https://medium.com/codex/5-killer-automation-scripts-in-python-42c273fc37c4) While making projects, we need some ready-made codes that can help us to solve our daily life problems. This article has **5 Automation Scripts** for your Python Projects that will solve these problems. So bookmark it and let’s get started. 1.) Photo Compressor -------------------- This will Compress your photos into lower sizes while the quality same. ``` import PIL from PIL import Image from tkinter.filedialog import * fl=askopenfilenames() img = Image.open(fl[0]) img.save("result.jpg", "JPEG", optimize = True, quality = 10) ``` 2.) Image Watermarker --------------------- This simple script will watermark any image. You can set the Text, location, and Font. ``` from PIL import Image from PIL import ImageFont from PIL import ImageDraw def watermark_img(img_path,res_path, text, pos): img = Image.open(img_path) wm = ImageDraw.Draw(img) col= (9, 3, 10) wm.text(pos, text, fill=col) img.show() img.save(res_path) img = 'initial.jpg' watermark_img(img, 'result.jpg','IshaanGupta', pos=(1, 0)) ``` **3.) Plagiarism Checker** -------------------------- This script checks Plagiarism between two files. ``` from difflib import SequenceMatcher def plagiarism_checker(f1,f2): with open(f1,errors="ignore") as file1,open(f2,errors="ignore") as file2: f1_data=file1.read() f2_data=file2.read() res=SequenceMatcher(None, f1_data, f2_data).ratio() print(f"These files are {res*100} % similar") f1=input("Enter file_1 path: ") f2=input("Enter file_2 path: ") plagiarism_checker(f1, f2) ``` 4.) File Encrypt and Decrypt ---------------------------- A small script that can Encrypt/Decrypt any file. ``` from cryptography.fernet import Fernet def encrypt(f_name, key): fernet = Fernet(key) with open(f_name, 'rb') as file: original = file.read() encrypted = fernet.encrypt(original) with open(f_name, 'wb') as enc_file: enc_file.write(encrypted) def decrypt(f_name, key): fernet = Fernet(key) with open(f_name, 'rb') as enc_file: encrypted = enc_file.read() decrypted = fernet.decrypt(encrypted) with open(f_name, 'wb') as dec_file: dec_file.write(decrypted) key = Fernet.generate_key() f_name = input("Enter Your filename: ") encrypt(f_name, key) decrypt(f_name, key) ``` **5.) Making URLs short** ------------------------- Sometimes big URLs become very annoying to read and share. This script uses an external API to short the URLs. ``` from __future__ import with_statement import contextlib try: from urllib.parse import urlencode except ImportError: from urllib import urlencode try: from urllib.request import urlopen except ImportError: from urllib2 import urlopen import sys def make_tiny(url): request_url = ('http://tinyurl.com/api-create.php?' + urlencode({'url':url})) with contextlib.closing(urlopen(request_url)) as response: return response.read().decode('utf-8') def main(): for tinyurl in map(make_tiny, sys.argv[1:]): print(tinyurl) if __name__ == '__main__': main() ```
Uploading file...
Edit message:
Cancel