Python Learning: Automate Boring Stuff with Python | Chapter 11 : My Solution to Multiplication Table Maker

Easier done than said ….like actually 03:35:23 Coffee with a drop of sleep in my eyes I am rather tired at the moment but have enough energy to solve this task: Multiplication table challenge.. # Usage: python multiplication.py <N> import sys import os import openpyxl import logging from openpyxl.styles import Font logging.basicConfig(level=logging.DEBUG, format=”%(asctime)s – %(levelname)s […]

“Python Learning: Automate Boring Stuff with Python | Chapter 11 : My Solution to Link Verification (with a twist)

Instead of downloading the pages, let’s just write the links out 4:40:41 PM In the last task we downloaded images directly to our machine into a folder in the current working directory. Since I am well acquainted with downloading files using requests, I decided to just write out the links into a text file instead […]

“Python Learning: Automate Boring Stuff with Python | Chapter 11 : My Solution to Image Downloader from Imgur

So you want to download images without a browser..  challenge accepted 3:43:41 PM   #Image Site Downloader #USAGE: python igmurdownloader.py <category> <limit> import sys, requests, os, logging, bs4, re logging.basicConfig(level=logging.DEBUG, format="%(asctime)s – %(levelname)s – %(message)s") logging.disable(logging.CRITICAL) if len(sys.argv) == 3: logging.info("Command line argument 3") #TODO: get category, and limit category = sys.argv[1] limit = sys.argv[2] imgur […]

“Python Learning: Automate Boring Stuff with Python | Chapter 11 : My Solution to Comic Downloader

Downloading a comic…. 9% 12:39:32 PM There is a solution provided in the book but this is my way of going around the task   #comic saver – saves each post of a comic page #USAGE python comic.py import logging, requests, bs4, os, sys logging.basicConfig(level=logging.DEBUG, format=” %(asctime)s – %(levelname)s – %(message)s”) #TODO: get url if len( […]

“Python Learning: Automate Boring Stuff with Python | Chapter 8 : My Solution to Practice Project: Filling in the Gaps

How to fill in the gaps 1:49:09 AM I need help with this! I like this exercise but I cannot seem to find its ideal solution. Could someone suggest in pseudocode, please..? # finds files with a give prefix in a folder # locates any gaps in the numbering # renames all the later files to […]

Python Learning: Automate Boring Stuff with Python | Chapter 8 : My Solution to Practice Project: Deleting Unneeded Files

Personally, one of the simplest projects yet This code (when properly indented) helps to list out all files with a size greater than the given limit.   # Usage python big.py limit in MB import sys import os if len(sys.argv) >= 2: limit = sys.argv[1] if len(sys.argv) == 3: source = sys.argv[2] else: source = […]

Python Learning: Automate Boring Stuff with Python | Chapter 8 : My Solution to Practice Project: Selective Copy

As usual… super simple automation.. I know it is quite trivial, but the fact that with a few lines of code I could re-organize my files based on their extensions makes coding really fun even outside of work. Code # selective copy # walks through a folder tree and searches for files with a certain […]

Python Learning: Automate Boring Stuff with Python | Making a directory and moving files into it

With this script we can make a new directory and move files with a given ending into the directory. This was not a task in the book, but just something I thought of solving. Quite interesting to know what you could do with string operations like “startWith” and “endWith”. # creates new directory and moves […]

Python Learning: Automate Boring Stuff with Python | Chapter 8 : My Solution to Project Regex Search

Searching through a list of text files in a given directory … I personally found this enjoyable. It was easier to solve compared to last problem. What I can say at this stage is, learn how to search to documentation and google! It helps… heheh.. oh yea, leave your suggestions in the comment box. see […]

Python Learning: Automate Boring Stuff with Python | Chapter 8 : My Solution to Project Madlib

Creating MadLib:   It was quite a task to solve this problem but worth it. I learned how to retrieve command line arguments using sys module, regex to match and search for the keyword in a given string, and os to create new files and open files.  I think a step further would be to […]

Python Learning: Automate Boring Stuff with Python | Chapter 8 : My Solution to Project Multiclipboard

# mcb.pyw : Saves and loads pieces of text to the clipboard # Usage: py.exe mcb.pyw save <keyword> – Saves clipboard to keyword # py.exe mcb.pyw <keyword> – Loads keyword to clipboard # py.exe mcb.pyw list – Loads all keywords to clipboard # py.exe mcb.pyw read <path text file> <keyword> import shelve import pyperclip import […]

Python Learning: Automate Boring Stuff with Python | Solution to Part II Chapter 7 Practice Project II

import re #first argument – string to be stripped #second argument – char or default ” ” def customStrip(string: str, stripChar: str=”\s”)->str: ”’ Removes specified character from the beginning and end of a given string arguments: string: str stripChar: str returns: string ”’ if stripChar == “” or stripChar == ” “: stripChar = “\s” […]

Python Learning: Automate Boring Stuff with Python | Solution to Part II Chapter 7 Practice Project I

Solution import re #eight chars long #upper and lower case chars #at least one digit patternHasDigit = re.compile(r”\d+”) patternHasLower = re.compile(r”[a-z]+”) patternHasUpper = re.compile(r”[A-Z]+”) patterns = (patternHasDigit, patternHasLower, patternHasUpper) tests = [“asdfgh57887”, “Asfkg35a”, “23454990-“,”ASHGFDSFGHFDSDFGDS”] for test in tests: status = True for pattern in patterns: if pattern.search(test) == None: print(“{} failed {} test”.format(test, pattern.pattern)) status = False […]