• Stars
    star
    197
  • Rank 197,722 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Short and fun Python scripts.

Build Status Dependency Status

This is a collection of short Python scripts I use in Linux. Portions of this README are automatically generated with generate-readme.py to insert the script-level comments as descriptions below.

Adding to your PATH

I have these added to my PATH variable to run from anywhere. Clone the repo and add the following to your bashrc or zshrc, replacing <python-scripts> with the location of the cloned repository. See my dotfiles repo for my complete Mac and Linux system configurations.

# Add additional directories to the path.
pathadd() {
  [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]] && PATH="${PATH:+"$PATH:"}$1"
}

pathadd <python-scripts>/python2.7
pathadd <python-scripts>/python3

Dependencies

These scripts are written in Python 3 except when external libraries don't support Python 3. Dependencies for Python 2 and 3 for all scripts are included in requirements-{2,3}.txt and can be installed using pip with pip3 install -r requirements-3.txt.

Travis CI

Continuous integration is provided by Travis CI here. .travis.yml calls .travis-script-2.sh and .travis-script-3.sh to ensure requirements-{2,3}.txt have all of the Python 2 and Python 3 scripts and that there are no careless errors that cause the scripts to not execute the help message. pep8 will fail the build if pep8 styling conventions aren't met.

Scripts

The subheadings link to the script contents on GitHub.

generate-readme.py

Generates the README for bamos/python-scripts so that the README and scripts contain synchronized documentation. Script descriptions are obtained by parsing the docstrings and inserted directly into the README as markdown.

python2.7/music-organizer.py

This script (music-organizer.py) organizes my music collection for iTunes and mpv using tag information. The directory structure is <artist>/<track>, where <artist> and <track> are lower case strings separated by dashes.

See my blog post Using Python to organize a music directory for a more detailed overview of this script.

python2.7/mt.py

This script implements the simple multitail example to tail multiple files and append the filename to the beginning of the output.

python2.7/caffe-compute-image-mean.py

This script computes the mean of a directory of images for Caffe.

python2.7/fix-music-tags.py

This script (fix-music-tags.py) mass-removes unwanted music tags.

python3/github-repo-summary.py

Produces a Markdown table concisely summarizing a list of GitHub repositories.

python3/link-checker.py

Script to be run by crontab to report broken links.

Builds upon linkchecker (Ubuntu: sudo apt-get install linkchecker) to hide warnings and to send a concise email if bad links are found.

Link checker screenshot

python3/phonetic.py

Obtain the NATO phonetic alphabet representation from short phrases.

$ phonetic.py github
g - golf
i - india
t - tango
h - hotel
u - uniform
b - bravo

python3/rank-writing.py

rank-writing.py ranks the writing quality of my blog's Markdown posts and my project's Markdown README files.

The following programs should be on your PATH:

$ rank-writing.py *.md

=== 2013-05-03-scraping-tables-python.md ===
Total: 53
β”œβ”€β”€ aspell: 34
β”œβ”€β”€ diction: 0
└── write-good: 19

...

=== 2013-04-16-pdf-from-plaintext.md ===
Total: 0
β”œβ”€β”€ aspell: 0
β”œβ”€β”€ diction: 0
└── write-good: 0

python3/get-osx-wallpaper.py

This is a Python script that outputs the path of the current OSX wallpaper. This is helpful when the desktop wallpaper is randomized across a large collection of pictures and you want to delete the current wallpaper.

Warning

  • This approach doesn't work with multiple monitors or virtual desktops.

Tested On

  • OSX Yosemite 10.10.2 with a single desktop on a MBP.

Usage

Ensure db_path and wallpaper_dir are correctly set below.

Assuming get-osx-wallpaper.py is on your path, check the output with the following

$ get-osx-wallpaper.py
/Users/bamos/Pictures/wallpaper/nature/496.jpg

Please ensure this is correct before trying to remove it!

This can be paired with other commands such as open or rm. Run killall Dock to refresh the changes after removing the file. Note that the dock will be restarted and all windows will be unminimized.

$ open $(get-osx-wallpaper.py)
$ rm $(get-osx-wallpaper.py) && killall Dock

Example alias definitions for bash and zsh are available in https://github.com/bamos/dotfiles/blob/master/.funcs:

alias open-wallpaper='open $(get-osx-wallpaper.py)'
alias rm-wallpaper='rm $(get-osx-wallpaper.py) && killall Dock'

python3/merge-pdfs-printable.py

The printers in my office print a cover page before every job, and I don't like printing many cover pages if I want to submit multiple papers separately so that the papers don't overlap. This script will merge PDF documents and insert blank pages so that the printed pages won't overlap documents. The modulo option is helpful to print 2 PDF pages per physical page side.

The script uses PyPDF2 to merge the documents and to extract the number of pages in the input documents and ghostscript to create a blank PDF page.

$ merge-pdfs-printable.py a.pdf b.pdf c.pdf --modulo 4
a.pdf
  + Pages: 6
  + Added 2 blank pages.
b.pdf
  + Pages: 13
  + Added 3 blank pages.
c.pdf
  + Pages: 13
  + Added 3 blank pages.
Merged output is in '/tmp/tmpm2n5g0mh-merge.pdf'.

Note: Some of my decrypted PDF documents have resulted in PyPDF2.utils.PdfReadError: file has not been decrypted. My current workaround solution is to run pdf2ps on the PDF and then ps2pdf on the PS file.

python3/remove-duplicates.py

Detect and remove duplicate images using average hashing.

http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html

python3/word-counter.py

Count work frequencies within a file.

$ word-counter.py shakespeare.md --numWords 4 --maxTuples 3

=== Sliding Window: 1 ===
    3473: 'shall'
    2238: 'would'
    2153: 'which'
    2074: 'their'

=== Sliding Window: 2 ===
    248: 'exeunt scene'
    117: 'second lord.'
    105: 'first lord.'
    102: 'queen elizabeth.'

=== Sliding Window: 3 ===
    36: 'william shakespeare dramatis'
    34: 'shakespeare dramatis personae'
    18: 'comes here? enter'
    14: 'duke's palace enter'

python3/eval-expr.py

A module to evaluate a mathematical expression using Python's AST.

If you want a command-line expression evaluator, use Russell91/pythonpy.

$ eval-expr.py '(((4+6)*10)<<2)'
(((4+6)*10)<<2) = 400

python3/merge-mutt-contacts.py

Merges two mutt contact files.

Similar Projects

There are many potpourri Python script repositories on GitHub. The following list shows a short sampling of projects, and I'm happy to merge pull requests of other projects.

Name Stargazers Description
averagesecurityguy/Python-Examples 26 Example scripts for common python tasks
ClarkGoble/Scripts 29 My scripts - primarily using python and appscript
computermacgyver/twitter-python 66 Simple example scripts for Twitter data collection with Tweepy in Python
gpambrozio/PythonScripts 38 A bunch of Python scripts I made and that might interest somebody else
realpython/python-scripts 568 because i'm tired of gists

More Repositories

1

dcgan-completion.tensorflow

Image Completion with Deep Learning in TensorFlow
Python
1,308
star
2

densenet.pytorch

A PyTorch implementation of DenseNet.
Python
823
star
3

cv

TeX
398
star
4

latex-templates

Website for personal collection and previewing of LaTeX templates. Presented with Python/Jinja2.
TeX
366
star
5

thesis

Differentiable Optimization-Based Modeling for Machine Learning
TeX
318
star
6

block

An intelligent block matrix library for numpy, PyTorch, and beyond.
Python
297
star
7

dotfiles

β™₯ Linux, xmonad, emacs, vim, zsh, tmux
Shell
238
star
8

zsh-history-analysis

Plot your .zsh_history.
Python
224
star
9

reading-list

My reading list.
CSS
185
star
10

presentations

TeX
141
star
11

beamer-snippets

Website for personal collection and previewing of Beamer and TikZ snippets. Presented with Python/Jinja2.
TeX
109
star
12

setGPU

Small Python library to automatically set CUDA_VISIBLE_DEVICES to the least loaded device on multi-GPU systems.
Python
106
star
13

parsec-benchmark

An unofficial mirror of the core PARSEC 3.0 benchmark suite with patches to run on x86_64 Arch Linux and generalize builds.
C
97
star
14

conference-tracker

Minimal-maintenance conference tracker.
Python
71
star
15

girl

Check your GitHub READMEs for broken links.
Scala
70
star
16

bamos.github.io

JavaScript
36
star
17

snowglobe

Haskell-driven, small-scale web analytics with minimal configuration.
Haskell
27
star
18

ecos.torch

Unofficial Torch ECOS bindings to solve linear programs (LPs) and second-order cone programs (SOCPs).
C
16
star
19

gurobi.torch

Unofficial Gurobi Torch bindings.
Lua
9
star
20

shell-scripts

Miscellaneous short shell scripts.
Shell
9
star
21

github-wiki-link-validator

Ensure all links in a Github Wiki point to valid locations within the Wiki.
Python
5
star
22

docker-llvm-polly-pocl

Build LLVM, Polly, and PoCL in an Ubuntu 12.04 Docker container.
Shell
4
star