From 741bac44fb73bbf62d1e6598afc25132d7aa5827 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Thu, 9 Jul 2015 06:37:46 -0400 Subject: [PATCH 01/18] Music organizer: Ignore ';' --- python2.7/music-organizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python2.7/music-organizer.py b/python2.7/music-organizer.py index 7437f1e..aa87cf3 100755 --- a/python2.7/music-organizer.py +++ b/python2.7/music-organizer.py @@ -65,7 +65,7 @@ def toNeat(s): s = s.lower().replace("&", "and") # Put spaces between and remove blank characters. - blankCharsPad = r"()\[\],.\\\?\#/\!\$\:" + blankCharsPad = r"()\[\],.\\\?\#/\!\$\:\;" blankCharsNoPad = r"'\"" s = re.sub(r"([" + blankCharsPad + r"])([^ ])", "\\1 \\2", s) s = re.sub("[" + blankCharsPad + blankCharsNoPad + "]", "", s) From 6cad2d60857e9d8714f679f68ae4887e58092a57 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Fri, 7 Aug 2015 11:14:12 -0400 Subject: [PATCH 02/18] Add caffe-compute-image-mean. --- python2.7/caffe-compute-image-mean.py | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 python2.7/caffe-compute-image-mean.py diff --git a/python2.7/caffe-compute-image-mean.py b/python2.7/caffe-compute-image-mean.py new file mode 100755 index 0000000..efe1e53 --- /dev/null +++ b/python2.7/caffe-compute-image-mean.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python2 + +import sys +sys.path.append("/home/bamos/repos/caffe-local/python") + +import argparse +import numpy as np +import os +import time + +from caffe.proto import caffe_pb2 +from caffe.io import array_to_blobproto +from collections import defaultdict +from skimage import io + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('meanPrefix', type=str, help="TODO") + parser.add_argument('imageDir', type=str, help="TODO") + args = parser.parse_args() + + exts = ["jpg", "png"] + + mean = np.zeros((1, 3, 152, 152)) + N = 0 + classSizes = defaultdict(int) + + beginTime = time.time() + for subdir, dirs, files in os.walk(args.imageDir): + for fName in files: + (imageClass, imageName) = (os.path.basename(subdir), fName) + if any(imageName.lower().endswith("." + ext) for ext in exts): + img = io.imread(os.path.join(subdir, fName)) + if img.shape == (152, 152, 3): + mean[0][0] += img[:,:,0] + mean[0][1] += img[:,:,1] + mean[0][2] += img[:,:,2] + N += 1 + if N % 1000 == 0: + elapsed = time.time() - beginTime + print("Processed {} images in {:.2f} seconds. " + "{:.2f} images/second.".format(N, elapsed, + N/elapsed)) + mean[0] /= N + + blob = array_to_blobproto(mean) + with open("{}.binaryproto".format(args.meanPrefix), 'wb') as f: + f.write(blob.SerializeToString()) + np.save("{}.npy".format(args.meanPrefix), mean[0]) + + meanImg = np.transpose(mean[0].astype(np.uint8), (1, 2, 0)) + io.imsave("{}.png".format(args.meanPrefix), meanImg) From aad7a8452d362a249aef95d196595b0b094f9aa5 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Fri, 7 Aug 2015 11:16:33 -0400 Subject: [PATCH 03/18] Caffe mean: Fill in TODO arg descriptions. --- python2.7/caffe-compute-image-mean.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python2.7/caffe-compute-image-mean.py b/python2.7/caffe-compute-image-mean.py index efe1e53..41698fb 100755 --- a/python2.7/caffe-compute-image-mean.py +++ b/python2.7/caffe-compute-image-mean.py @@ -15,8 +15,8 @@ if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('meanPrefix', type=str, help="TODO") - parser.add_argument('imageDir', type=str, help="TODO") + parser.add_argument('meanPrefix', type=str, help="Prefix of the mean file.") + parser.add_argument('imageDir', type=str, help="Directory of images to read.") args = parser.parse_args() exts = ["jpg", "png"] From 318e6bbfca6228a95da56f0c24e838c3439e00dd Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Sun, 9 Aug 2015 21:56:24 -0400 Subject: [PATCH 04/18] Link Checker: Check external URLs. --- python3/link-checker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python3/link-checker.py b/python3/link-checker.py index 097d74f..93e40fa 100755 --- a/python3/link-checker.py +++ b/python3/link-checker.py @@ -27,7 +27,7 @@ email_from = ENTER_FROM_EMAIL root_url = ENTER_URL -cmd = ["linkchecker", "--no-warnings", "--no-status", root_url] +cmd = ["linkchecker", "--no-warnings", "--no-status", "--external", root_url] output = Popen(cmd, stdout=PIPE).communicate()[0].decode("UTF-8") bad_urls = [] From 2a2fa468038dd9a9e3ad3e2703adf7f854de0f83 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Mon, 10 Aug 2015 07:38:03 -0400 Subject: [PATCH 05/18] Caffe Image Mean: Fix pep8 warnings. --- python2.7/caffe-compute-image-mean.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python2.7/caffe-compute-image-mean.py b/python2.7/caffe-compute-image-mean.py index 41698fb..e1ce475 100755 --- a/python2.7/caffe-compute-image-mean.py +++ b/python2.7/caffe-compute-image-mean.py @@ -32,15 +32,15 @@ if any(imageName.lower().endswith("." + ext) for ext in exts): img = io.imread(os.path.join(subdir, fName)) if img.shape == (152, 152, 3): - mean[0][0] += img[:,:,0] - mean[0][1] += img[:,:,1] - mean[0][2] += img[:,:,2] + mean[0][0] += img[:, :, 0] + mean[0][1] += img[:, :, 1] + mean[0][2] += img[:, :, 2] N += 1 if N % 1000 == 0: elapsed = time.time() - beginTime print("Processed {} images in {:.2f} seconds. " "{:.2f} images/second.".format(N, elapsed, - N/elapsed)) + N / elapsed)) mean[0] /= N blob = array_to_blobproto(mean) From 1b31c571377615c8a2a77d332adc7d12904b371e Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Mon, 10 Aug 2015 08:22:29 -0400 Subject: [PATCH 06/18] Caffe Image Mean: Add description. --- python2.7/caffe-compute-image-mean.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python2.7/caffe-compute-image-mean.py b/python2.7/caffe-compute-image-mean.py index e1ce475..ea648d7 100755 --- a/python2.7/caffe-compute-image-mean.py +++ b/python2.7/caffe-compute-image-mean.py @@ -1,5 +1,12 @@ #!/usr/bin/env python2 +__author__ = ['[Brandon Amos](http://bamos.github.io)'] +__date__ = '2015.08.10' + +""" +This script computes the mean of a directory of images for Caffe. +""" + import sys sys.path.append("/home/bamos/repos/caffe-local/python") From 31c8e434d2092c3219a010020a306b67465c14b2 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Mon, 10 Aug 2015 08:22:36 -0400 Subject: [PATCH 07/18] Update auto-generated README. --- README.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 891afc4..05b91ad 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,15 @@ and inserted directly into the README as markdown. +## [python2.7/caffe-compute-image-mean.py](https://github.com/bamos/python-scripts/blob/master/python2.7/caffe-compute-image-mean.py) ++ Authors: [Brandon Amos](http://bamos.github.io) ++ Created: 2015.08.10 + + +This script computes the mean of a directory of images for Caffe. + + + ## [python2.7/mt.py](https://github.com/bamos/python-scripts/blob/master/python2.7/mt.py) + Authors: [Brandon Amos](http://bamos.github.io) + Created: 2014.11.30 @@ -337,7 +346,7 @@ and I'm happy to merge pull requests of other projects. Name | Stargazers | Description ----|----|---- [averagesecurityguy/Python-Examples](https://github.com/averagesecurityguy/Python-Examples) | 20 | Example scripts for common python tasks -[ClarkGoble/Scripts](https://github.com/ClarkGoble/Scripts) | 26 | My scripts - primarily using python and appscript -[computermacgyver/twitter-python](https://github.com/computermacgyver/twitter-python) | 45 | Simple example scripts for Twitter data collection with Tweepy in Python -[gpambrozio/PythonScripts](https://github.com/gpambrozio/PythonScripts) | 39 | A bunch of Python scripts I made and that might interest somebody else -[realpython/python-scripts](https://github.com/realpython/python-scripts) | 59 | because i'm tired of gists +[ClarkGoble/Scripts](https://github.com/ClarkGoble/Scripts) | 28 | My scripts - primarily using python and appscript +[computermacgyver/twitter-python](https://github.com/computermacgyver/twitter-python) | 50 | Simple example scripts for Twitter data collection with Tweepy in Python +[gpambrozio/PythonScripts](https://github.com/gpambrozio/PythonScripts) | 38 | A bunch of Python scripts I made and that might interest somebody else +[realpython/python-scripts](https://github.com/realpython/python-scripts) | 66 | because i'm tired of gists From b9a4461b509c7447cbb2273ba711ad413a75f5c2 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Tue, 25 Aug 2015 16:32:17 -0400 Subject: [PATCH 08/18] Fix broken link. --- python3/get-osx-wallpaper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python3/get-osx-wallpaper.py b/python3/get-osx-wallpaper.py index 74e349c..1feb0dc 100755 --- a/python3/get-osx-wallpaper.py +++ b/python3/get-osx-wallpaper.py @@ -41,7 +41,7 @@ ``` Example alias definitions for bash and zsh are available in -https://github.com/bamos/dotfiles/blob/master/.aliases: +https://github.com/bamos/dotfiles/blob/master/.funcs: ``` alias open-wallpaper='open $(get-osx-wallpaper.py)' From e530c468643cbf26115217b5c4692fe1ea5d3734 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Tue, 25 Aug 2015 16:32:30 -0400 Subject: [PATCH 09/18] Update auto-generated README. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 05b91ad..7776e8f 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ $ rm $(get-osx-wallpaper.py) && killall Dock ``` Example alias definitions for bash and zsh are available in -https://github.com/bamos/dotfiles/blob/master/.aliases: +https://github.com/bamos/dotfiles/blob/master/.funcs: ``` alias open-wallpaper='open $(get-osx-wallpaper.py)' @@ -349,4 +349,4 @@ Name | Stargazers | Description [ClarkGoble/Scripts](https://github.com/ClarkGoble/Scripts) | 28 | My scripts - primarily using python and appscript [computermacgyver/twitter-python](https://github.com/computermacgyver/twitter-python) | 50 | Simple example scripts for Twitter data collection with Tweepy in Python [gpambrozio/PythonScripts](https://github.com/gpambrozio/PythonScripts) | 38 | A bunch of Python scripts I made and that might interest somebody else -[realpython/python-scripts](https://github.com/realpython/python-scripts) | 66 | because i'm tired of gists +[realpython/python-scripts](https://github.com/realpython/python-scripts) | 67 | because i'm tired of gists From 1b3aabb9e8a09573f04f6f3795454a3db217246c Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Wed, 30 Dec 2015 11:30:01 -0500 Subject: [PATCH 10/18] Add fix-music-tags script. --- README.md | 17 ++++++++++++---- python2.7/fix-music-tags.py | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100755 python2.7/fix-music-tags.py diff --git a/README.md b/README.md index 7776e8f..eee0a20 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,15 @@ This script computes the mean of a directory of images for Caffe. +## [python2.7/fix-music-tags.py](https://github.com/bamos/python-scripts/blob/master/python2.7/fix-music-tags.py) ++ Authors: [Brandon Amos](http://bamos.github.io) ++ Created: 2015.12.30 + + +This script (fix-music-tags.py) mass-removes unwanted music tags. + + + ## [python2.7/mt.py](https://github.com/bamos/python-scripts/blob/master/python2.7/mt.py) + Authors: [Brandon Amos](http://bamos.github.io) + Created: 2014.11.30 @@ -345,8 +354,8 @@ and I'm happy to merge pull requests of other projects. Name | Stargazers | Description ----|----|---- -[averagesecurityguy/Python-Examples](https://github.com/averagesecurityguy/Python-Examples) | 20 | Example scripts for common python tasks -[ClarkGoble/Scripts](https://github.com/ClarkGoble/Scripts) | 28 | My scripts - primarily using python and appscript -[computermacgyver/twitter-python](https://github.com/computermacgyver/twitter-python) | 50 | Simple example scripts for Twitter data collection with Tweepy in Python +[averagesecurityguy/Python-Examples](https://github.com/averagesecurityguy/Python-Examples) | 22 | Example scripts for common python tasks +[ClarkGoble/Scripts](https://github.com/ClarkGoble/Scripts) | 29 | My scripts - primarily using python and appscript +[computermacgyver/twitter-python](https://github.com/computermacgyver/twitter-python) | 62 | Simple example scripts for Twitter data collection with Tweepy in Python [gpambrozio/PythonScripts](https://github.com/gpambrozio/PythonScripts) | 38 | A bunch of Python scripts I made and that might interest somebody else -[realpython/python-scripts](https://github.com/realpython/python-scripts) | 67 | because i'm tired of gists +[realpython/python-scripts](https://github.com/realpython/python-scripts) | 549 | because i'm tired of gists diff --git a/python2.7/fix-music-tags.py b/python2.7/fix-music-tags.py new file mode 100755 index 0000000..7beddff --- /dev/null +++ b/python2.7/fix-music-tags.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python2 + +__author__ = ['[Brandon Amos](http://bamos.github.io)'] +__date__ = '2015.12.30' + +""" +This script (fix-music-tags.py) mass-removes unwanted music tags. +""" + +from mutagen.easyid3 import EasyID3 +import argparse +import glob + + +def fixTags(fname, keep): + audio = EasyID3(fname) + artist = audio['artist'] + title = audio['title'] + album = audio['album'] + + delKeys = [] + for k, v in audio.items(): + if k not in keep: + delKeys.append(k) + + for k in delKeys: + del audio[k] + audio.save() + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('directory', help='Directory with mp3 files to fix.') + parser.add_argument('--keep', default=['title', 'artist', 'album', 'genre'], + type=str, nargs='+', metavar='TAG', + help="Tags to keep. Default: title, artist, album, genre") + args = parser.parse_args() + + for fname in glob.glob("{}/*.mp3".format(args.directory)): + print("Fixing tags for {}".format(fname)) + fixTags(fname, args.keep) From acc7e0b3366c263cff238220d1034d5d93c24dbe Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Fri, 1 Jan 2016 21:51:50 -0500 Subject: [PATCH 11/18] Travis: Use flake8 and correct flake8 warnings. --- .travis-script-2.sh | 2 +- .travis-script-3.sh | 2 +- python2.7/caffe-compute-image-mean.py | 1 - python2.7/fix-music-tags.py | 3 --- python3/github-repo-summary.py | 4 +--- python3/link-checker.py | 10 +++++----- python3/merge-pdfs-printable.py | 3 +-- python3/remove-duplicates.py | 4 ++-- 8 files changed, 11 insertions(+), 18 deletions(-) diff --git a/.travis-script-2.sh b/.travis-script-2.sh index 15aca56..c5b43ce 100755 --- a/.travis-script-2.sh +++ b/.travis-script-2.sh @@ -5,5 +5,5 @@ set -x -e # Show commands being executed and exit nonzero upon errors. ./python2.7/mt.py --help for F in python2.7/*; do - pep8 --ignore=E402,E501 $F + flake8 --ignore=E402,E501 $F done diff --git a/.travis-script-3.sh b/.travis-script-3.sh index d933f51..1abf542 100755 --- a/.travis-script-3.sh +++ b/.travis-script-3.sh @@ -13,5 +13,5 @@ set -x -e # Show commands being executed and exit nonzero upon errors. ./python3/merge-mutt-contacts.py --help for F in generate-readme.py python3/*; do - pep8 --ignore=E402,E501 $F + flake8 --ignore=E402,E501 $F done diff --git a/python2.7/caffe-compute-image-mean.py b/python2.7/caffe-compute-image-mean.py index ea648d7..d5b8540 100755 --- a/python2.7/caffe-compute-image-mean.py +++ b/python2.7/caffe-compute-image-mean.py @@ -15,7 +15,6 @@ import os import time -from caffe.proto import caffe_pb2 from caffe.io import array_to_blobproto from collections import defaultdict from skimage import io diff --git a/python2.7/fix-music-tags.py b/python2.7/fix-music-tags.py index 7beddff..8e07eb2 100755 --- a/python2.7/fix-music-tags.py +++ b/python2.7/fix-music-tags.py @@ -14,9 +14,6 @@ def fixTags(fname, keep): audio = EasyID3(fname) - artist = audio['artist'] - title = audio['title'] - album = audio['album'] delKeys = [] for k, v in audio.items(): diff --git a/python3/github-repo-summary.py b/python3/github-repo-summary.py index aece884..e59e96c 100755 --- a/python3/github-repo-summary.py +++ b/python3/github-repo-summary.py @@ -9,7 +9,6 @@ from github import Github import argparse -import time import os import sys @@ -30,8 +29,7 @@ def sanitize_for_md(s): try: r = github.get_repo(r_name) except: - print("Error: Repository '{}' not found.".format(r_name), - file=sys.stderr) + sys.stderr.write("Error: Repository '{}' not found.\n".format(r_name)) sys.exit(-1) content = " | ".join([ "[{}]({})".format(r.full_name, r.html_url), diff --git a/python3/link-checker.py b/python3/link-checker.py index 93e40fa..846ff66 100755 --- a/python3/link-checker.py +++ b/python3/link-checker.py @@ -21,11 +21,11 @@ # Settings to send emails with SMTP with gmail. server = "smtp.gmail.com" port = 587 -user = ENTER_USER -pw = ENTER_PW # Please use an application-specific password for security! -email_to = ENTER_TO_EMAIL -email_from = ENTER_FROM_EMAIL -root_url = ENTER_URL +user = 'ENTER_USER' +pw = 'ENTER_PW' # Please use an application-specific password for security! +email_to = 'ENTER_TO_EMAIL' +email_from = 'ENTER_FROM_EMAIL' +root_url = 'ENTER_URL' cmd = ["linkchecker", "--no-warnings", "--no-status", "--external", root_url] output = Popen(cmd, stdout=PIPE).communicate()[0].decode("UTF-8") diff --git a/python3/merge-pdfs-printable.py b/python3/merge-pdfs-printable.py index c88a840..d2c2cd4 100755 --- a/python3/merge-pdfs-printable.py +++ b/python3/merge-pdfs-printable.py @@ -37,7 +37,6 @@ import argparse import os -import re import subprocess import tempfile @@ -87,7 +86,7 @@ def merge_pdfs(f_names): out_file = "merged.pdf" # tempfile.mktemp("-merge.pdf") with open(out_file, 'wb') as f: merger.write(f) - [f.close() for f in fps] + [fp.close() for fp in fps] print("Merged output is in '{}'.".format(out_file)) if __name__ == '__main__': diff --git a/python3/remove-duplicates.py b/python3/remove-duplicates.py index 1158f2f..d2bb442 100755 --- a/python3/remove-duplicates.py +++ b/python3/remove-duplicates.py @@ -13,7 +13,6 @@ import hashlib import imagehash import os -import sys from collections import defaultdict from PIL import Image @@ -27,7 +26,8 @@ def getImgs(d): for subdir, dirs, files in os.walk(d): imgs = [] for fName in files: - (imageClass, imageName) = (os.path.basename(subdir), fName) + # (imageClass, imageName) = (os.path.basename(subdir), fName) + imageName = fName if any(imageName.lower().endswith("." + ext) for ext in exts): imgs.append(os.path.join(subdir, fName)) imgClasses.append(imgs) From e17f06880eef2bede0072314912611d0e9175b48 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Sat, 2 Jan 2016 04:33:50 -0500 Subject: [PATCH 12/18] Travis: Attempt to fix build error. --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3f7ec4c..6de3050 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,15 @@ +sudo: False language: python python: - "2.7" - "3.4" +addons: + apt: + packages: + - gfortran + - libatlas-base-dev install: - - sudo apt-get -qq install libatlas-base-dev gfortran - if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then pip install -r requirements-2.txt; fi - if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then travis_wait pip install -r requirements-3.txt; fi - pip install pep8 From 440bc6834213f51da0e0d9380e04fad8bc849576 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Sat, 2 Jan 2016 04:34:48 -0500 Subject: [PATCH 13/18] Travis: pep8->flake8 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6de3050..17a7386 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ addons: install: - if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then pip install -r requirements-2.txt; fi - if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then travis_wait pip install -r requirements-3.txt; fi - - pip install pep8 + - pip install flake8 # Ensure `requirements.txt` contains all of the dependencies # for the scripts and that scripts that only operate on From 9db0fb8a36af9109586154aae2cc2d83e0081bcc Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Sat, 2 Jan 2016 04:35:25 -0500 Subject: [PATCH 14/18] Update copyright in LICENSE. --- LICENSE.mit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.mit b/LICENSE.mit index aba7989..15f69c3 100644 --- a/LICENSE.mit +++ b/LICENSE.mit @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2013 Brandon Amos +Copyright (c) 2013-2016 Brandon Amos Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 669919248d8fe0e6d81113fbacc75a9476a7a169 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Mon, 4 Jan 2016 14:35:46 -0500 Subject: [PATCH 15/18] music-organizer: Ignore dotfiles. --- python2.7/music-organizer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python2.7/music-organizer.py b/python2.7/music-organizer.py index aa87cf3..1bed95e 100755 --- a/python2.7/music-organizer.py +++ b/python2.7/music-organizer.py @@ -15,6 +15,7 @@ """ import argparse +import glob import os import re import shutil @@ -194,7 +195,7 @@ def song(filename): def collection(): - for f in os.listdir("."): + for f in glob.glob('*'): if os.path.isdir(f): if f != 'iTunes' and f != 'playlists': artist(f) From 9977e591c0fced3653c940dad501a642a4a73739 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Tue, 2 Feb 2016 14:15:11 -0500 Subject: [PATCH 16/18] Update auto-generated README. --- README.md | 226 +++++++++++++++++++++++++++--------------------------- 1 file changed, 113 insertions(+), 113 deletions(-) diff --git a/README.md b/README.md index eee0a20..f8893fb 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,34 @@ and inserted directly into the README as markdown. +## [python2.7/music-organizer.py](https://github.com/bamos/python-scripts/blob/master/python2.7/music-organizer.py) ++ Authors: [Brandon Amos](http://bamos.github.io) ++ Created: 2014.04.19 + + +This script (music-organizer.py) organizes my music collection for +iTunes and [mpv](http://mpv.io) using tag information. +The directory structure is `/`, where `` and `` +are lower case strings separated by dashes. + +See my blog post +[Using Python to organize a music directory](http://bamos.github.io/2014/07/05/music-organizer/) +for a more detailed overview of this script. + + + +## [python2.7/mt.py](https://github.com/bamos/python-scripts/blob/master/python2.7/mt.py) ++ Authors: [Brandon Amos](http://bamos.github.io) ++ Created: 2014.11.30 + + +This script implements the simple +[multitail](https://pypi.python.org/pypi/multitail) +example to tail multiple files and append the filename to the beginning +of the output. + + + ## [python2.7/caffe-compute-image-mean.py](https://github.com/bamos/python-scripts/blob/master/python2.7/caffe-compute-image-mean.py) + Authors: [Brandon Amos](http://bamos.github.io) + Created: 2015.08.10 @@ -83,51 +111,78 @@ This script (fix-music-tags.py) mass-removes unwanted music tags. -## [python2.7/mt.py](https://github.com/bamos/python-scripts/blob/master/python2.7/mt.py) +## [python3/github-repo-summary.py](https://github.com/bamos/python-scripts/blob/master/python3/github-repo-summary.py) + Authors: [Brandon Amos](http://bamos.github.io) -+ Created: 2014.11.30 ++ Created: 2014.11.02 -This script implements the simple -[multitail](https://pypi.python.org/pypi/multitail) -example to tail multiple files and append the filename to the beginning -of the output. +Produces a Markdown table concisely summarizing a list of GitHub repositories. -## [python2.7/music-organizer.py](https://github.com/bamos/python-scripts/blob/master/python2.7/music-organizer.py) +## [python3/link-checker.py](https://github.com/bamos/python-scripts/blob/master/python3/link-checker.py) + Authors: [Brandon Amos](http://bamos.github.io) -+ Created: 2014.04.19 ++ Created: 2014.02.06 -This script (music-organizer.py) organizes my music collection for -iTunes and [mpv](http://mpv.io) using tag information. -The directory structure is `/`, where `` and `` -are lower case strings separated by dashes. +Script to be run by crontab to report broken links. -See my blog post -[Using Python to organize a music directory](http://bamos.github.io/2014/07/05/music-organizer/) -for a more detailed overview of this script. +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](https://raw.githubusercontent.com/bamos/python-scripts/master/link-checker-screenshot.png?raw=true) -## [python3/eval-expr.py](https://github.com/bamos/python-scripts/blob/master/python3/eval-expr.py) -+ Authors: J. Sebastian, [Brandon Amos](http://bamos.github.io) -+ Created: 2013.08.01 +## [python3/phonetic.py](https://github.com/bamos/python-scripts/blob/master/python3/phonetic.py) ++ Authors: [Brandon Amos](http://bamos.github.io) ++ Created: 2014.02.14 -A module to evaluate a mathematical expression using Python's AST. -+ Original by: J. Sebastian at http://stackoverflow.com/questions/2371436. -+ Modifications by: [Brandon Amos](http://bamos.github.io). +Obtain the NATO phonetic alphabet representation from short phrases. -If you want a command-line expression evaluator, use -[Russell91/pythonpy](https://github.com/Russell91/pythonpy). +``` +$ phonetic.py github +g - golf +i - india +t - tango +h - hotel +u - uniform +b - bravo +``` + + + +## [python3/rank-writing.py](https://github.com/bamos/python-scripts/blob/master/python3/rank-writing.py) ++ Authors: [Brandon Amos](http://bamos.github.io) ++ Created: 2014.02.14 + + +`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`: ++ [aspell](http://aspell.net/) ++ [write-good](https://github.com/btford/write-good) ++ [diction](https://www.gnu.org/software/diction/) ``` -$ eval-expr.py '(((4+6)*10)<<2)' -(((4+6)*10)<<2) = 400 +$ 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 ``` @@ -183,38 +238,6 @@ alias rm-wallpaper='rm $(get-osx-wallpaper.py) && killall Dock' -## [python3/github-repo-summary.py](https://github.com/bamos/python-scripts/blob/master/python3/github-repo-summary.py) -+ Authors: [Brandon Amos](http://bamos.github.io) -+ Created: 2014.11.02 - - -Produces a Markdown table concisely summarizing a list of GitHub repositories. - - - -## [python3/link-checker.py](https://github.com/bamos/python-scripts/blob/master/python3/link-checker.py) -+ Authors: [Brandon Amos](http://bamos.github.io) -+ Created: 2014.02.06 - - -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](https://raw.githubusercontent.com/bamos/python-scripts/master/link-checker-screenshot.png?raw=true) - - - -## [python3/merge-mutt-contacts.py](https://github.com/bamos/python-scripts/blob/master/python3/merge-mutt-contacts.py) -+ Authors: [Brandon Amos](http://bamos.github.io) -+ Created: 2014.01.08 - - -Merges two mutt contact files. - - - ## [python3/merge-pdfs-printable.py](https://github.com/bamos/python-scripts/blob/master/python3/merge-pdfs-printable.py) + Authors: [Brandon Amos](http://bamos.github.io) + Created: 2014.10.17 @@ -252,59 +275,6 @@ PS file. -## [python3/phonetic.py](https://github.com/bamos/python-scripts/blob/master/python3/phonetic.py) -+ Authors: [Brandon Amos](http://bamos.github.io) -+ Created: 2014.02.14 - - -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](https://github.com/bamos/python-scripts/blob/master/python3/rank-writing.py) -+ Authors: [Brandon Amos](http://bamos.github.io) -+ Created: 2014.02.14 - - -`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`: -+ [aspell](http://aspell.net/) -+ [write-good](https://github.com/btford/write-good) -+ [diction](https://www.gnu.org/software/diction/) - - -``` -$ 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/remove-duplicates.py](https://github.com/bamos/python-scripts/blob/master/python3/remove-duplicates.py) + Authors: [Brandon Amos](http://bamos.github.io) + Created: 2015.06.06 @@ -347,6 +317,36 @@ $ word-counter.py shakespeare.md --numWords 4 --maxTuples 3 +## [python3/eval-expr.py](https://github.com/bamos/python-scripts/blob/master/python3/eval-expr.py) ++ Authors: J. Sebastian, [Brandon Amos](http://bamos.github.io) ++ Created: 2013.08.01 + + +A module to evaluate a mathematical expression using Python's AST. + ++ Original by: J. Sebastian at http://stackoverflow.com/questions/2371436. ++ Modifications by: [Brandon Amos](http://bamos.github.io). + +If you want a command-line expression evaluator, use +[Russell91/pythonpy](https://github.com/Russell91/pythonpy). + + +``` +$ eval-expr.py '(((4+6)*10)<<2)' +(((4+6)*10)<<2) = 400 +``` + + + +## [python3/merge-mutt-contacts.py](https://github.com/bamos/python-scripts/blob/master/python3/merge-mutt-contacts.py) ++ Authors: [Brandon Amos](http://bamos.github.io) ++ Created: 2014.01.08 + + +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, @@ -354,8 +354,8 @@ and I'm happy to merge pull requests of other projects. Name | Stargazers | Description ----|----|---- -[averagesecurityguy/Python-Examples](https://github.com/averagesecurityguy/Python-Examples) | 22 | Example scripts for common python tasks +[averagesecurityguy/Python-Examples](https://github.com/averagesecurityguy/Python-Examples) | 26 | Example scripts for common python tasks [ClarkGoble/Scripts](https://github.com/ClarkGoble/Scripts) | 29 | My scripts - primarily using python and appscript -[computermacgyver/twitter-python](https://github.com/computermacgyver/twitter-python) | 62 | Simple example scripts for Twitter data collection with Tweepy in Python +[computermacgyver/twitter-python](https://github.com/computermacgyver/twitter-python) | 66 | Simple example scripts for Twitter data collection with Tweepy in Python [gpambrozio/PythonScripts](https://github.com/gpambrozio/PythonScripts) | 38 | A bunch of Python scripts I made and that might interest somebody else -[realpython/python-scripts](https://github.com/realpython/python-scripts) | 549 | because i'm tired of gists +[realpython/python-scripts](https://github.com/realpython/python-scripts) | 568 | because i'm tired of gists From eedfec09409e385f676b2beeeda03ed0bfb8bb2f Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Sun, 10 Apr 2016 06:19:38 -0400 Subject: [PATCH 17/18] Initial commit of music-autoplaylists. --- python2.7/music-autoplaylists.py | 74 ++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 python2.7/music-autoplaylists.py diff --git a/python2.7/music-autoplaylists.py b/python2.7/music-autoplaylists.py new file mode 100755 index 0000000..f764076 --- /dev/null +++ b/python2.7/music-autoplaylists.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python2.7 + +__author__ = ['[Brandon Amos](http://bamos.github.io)'] +__date__ = '2015.04.09' + +""" +This script (music-autoplaylists.py) automatically creates +M3U playlists from the genre ID3 tags of songs in a directory. +""" + +import argparse +import os +import re +import shutil +import sys +from mutagen.easyid3 import EasyID3 +from collections import defaultdict + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--musicDir', type=str, default='.') + parser.add_argument('--playlistDir', type=str, default='./playlists/auto') + args = parser.parse_args() + + genres = defaultdict(list) + for dpath, dnames, fnames in os.walk(args.musicDir): + if '.git' in dpath: continue + for fname in fnames: + if os.path.splitext(fname)[1] != '.mp3': continue + p = os.path.abspath(os.path.join(dpath, fname)) + audio = EasyID3(p) + if 'genre' in audio: + assert(len(audio['genre']) == 1) + genre = toNeat(str(audio['genre'][0])) + else: + genre = 'Unknown' + genres[genre].append(p) + + if os.path.exists(args.playlistDir): + shutil.rmtree(args.playlistDir) + os.makedirs(args.playlistDir) + + for genre, songs in genres.items(): + p = os.path.join(args.playlistDir, genre+'.m3u') + print("Creating playlist: {}".format(p)) + with open(p, 'w') as f: + f.write("#EXTM3U\n") + f.write("\n".join(sorted(songs))+"\n") + +# Maps a string such as 'The Beatles' to 'the-beatles'. +def toNeat(s): + s = s.lower().replace("&", "and") + + # Put spaces between and remove blank characters. + blankCharsPad = r"()\[\],.\\\?\#/\!\$\:\;" + blankCharsNoPad = r"'\"" + s = re.sub(r"([" + blankCharsPad + r"])([^ ])", "\\1 \\2", s) + s = re.sub("[" + blankCharsPad + blankCharsNoPad + "]", "", s) + + # Replace spaces with a single dash. + s = re.sub(r"[ \*\_]+", "-", s) + s = re.sub("-+", "-", s) + s = re.sub("^-*", "", s) + s = re.sub("-*$", "", s) + + # Ensure the string is only alphanumeric with '-', '+', and '='. + search = re.search("[^0-9a-z\-\+\=]", s) + if search: + print("Error: Unrecognized character in '" + s + "'") + sys.exit(-42) + return s + +if __name__ == '__main__': + main() From 284e62e741ba8ac0c65f89cd51e5a7e7c8abe3c1 Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Fri, 22 Apr 2016 22:17:12 -0400 Subject: [PATCH 18/18] Fix flake warnings. --- python2.7/music-autoplaylists.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/python2.7/music-autoplaylists.py b/python2.7/music-autoplaylists.py index f764076..15759bf 100755 --- a/python2.7/music-autoplaylists.py +++ b/python2.7/music-autoplaylists.py @@ -16,6 +16,7 @@ from mutagen.easyid3 import EasyID3 from collections import defaultdict + def main(): parser = argparse.ArgumentParser() parser.add_argument('--musicDir', type=str, default='.') @@ -24,9 +25,11 @@ def main(): genres = defaultdict(list) for dpath, dnames, fnames in os.walk(args.musicDir): - if '.git' in dpath: continue + if '.git' in dpath: + continue for fname in fnames: - if os.path.splitext(fname)[1] != '.mp3': continue + if os.path.splitext(fname)[1] != '.mp3': + continue p = os.path.abspath(os.path.join(dpath, fname)) audio = EasyID3(p) if 'genre' in audio: @@ -41,13 +44,15 @@ def main(): os.makedirs(args.playlistDir) for genre, songs in genres.items(): - p = os.path.join(args.playlistDir, genre+'.m3u') + p = os.path.join(args.playlistDir, genre + '.m3u') print("Creating playlist: {}".format(p)) with open(p, 'w') as f: f.write("#EXTM3U\n") - f.write("\n".join(sorted(songs))+"\n") + f.write("\n".join(sorted(songs)) + "\n") # Maps a string such as 'The Beatles' to 'the-beatles'. + + def toNeat(s): s = s.lower().replace("&", "and")