Skip to content

Commit d0deac3

Browse files
committed
Initial commit of new README generation for bamos#3.
1 parent 1706428 commit d0deac3

13 files changed

Lines changed: 290 additions & 95 deletions

‎generate-readme.py‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python3
2+
3+
__author__ = ['Brandon Amos <http://github.com/bamos>']
4+
__date__ = '2015.03.27'
5+
6+
"""
7+
Generates the README for
8+
[bamos/python-scripts](https://github.com/bamos/python-scripts).
9+
Script descriptions are obtained by parsing the docstrings.
10+
"""
11+
12+
import ast
13+
import glob
14+
import os
15+
from jinja2 import Template
16+
from subprocess import Popen,PIPE
17+
18+
readme = Template("""
19+
This is a collection of short Python scripts I have added to my
20+
`PATH` variable to run from anywhere.
21+
None are currently available in [pip][pip],
22+
but I will add them if enough people are interested.
23+
24+
To add these to your `PATH`, clone the repo and add the following
25+
to your `bashrc` or `zshrc`, replacing `<python-scripts>`
26+
with the location of the cloned repository.
27+
Furthermore, see my [dotfiles][dotfiles] repo for my
28+
complete Mac and Linux system configurations.
29+
30+
```Bash
31+
# Add additional directories to the path.
32+
pathadd() {
33+
[ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]] && PATH="${PATH:+"$PATH:"}$1"
34+
}
35+
36+
pathadd <python-scripts>/python2.7
37+
pathadd <python-scripts>/python3
38+
```
39+
40+
[pip]: http://pip.readthedocs.org/en/latest/
41+
[dotfiles]: https://github.com/bamos/dotfiles
42+
43+
# Script Descriptions
44+
{{descriptions}}
45+
46+
# Similar Projects
47+
There are many potpourri Python script repositories on GitHub.
48+
The following list shows a short sampling of projects,
49+
and I'm happy to merge pull requests of other projects.
50+
51+
{{similar_projects}}
52+
""")
53+
54+
def get_docstr(filename):
55+
print(" + get_docstr({})".format(filename))
56+
with open(filename) as f:
57+
script = ast.parse(f.read())
58+
try:
59+
authors,date,desc = map(lambda x: ast.literal_eval(x.value),
60+
script.body[0:3])
61+
except:
62+
print(" + Error reading (author,date,desc).")
63+
raise
64+
return """
65+
## {}
66+
+ Authors: {}
67+
+ Date Created: {}
68+
69+
{}
70+
""".format(filename, ", ".join(authors), date, desc)
71+
72+
def get_descriptions():
73+
print("# Getting project descriptions")
74+
return ("\n".join(map(get_docstr,
75+
['generate-readme.py']+glob.glob("python*/*.py"))))
76+
77+
def get_similar_projects():
78+
print("# Getting similar projects")
79+
projs =['gpambrozio/PythonScripts',
80+
'ClarkGoble/Scripts',
81+
'gpambrozio/PythonScripts',
82+
'realpython/python-scripts',
83+
'averagesecurityguy/Python-Examples',
84+
'computermacgyver/twitter-python']
85+
cmd = ['./python3/github-repo-summary.py'] + projs
86+
p = Popen(cmd, stdout=PIPE)
87+
out,err = p.communicate()
88+
return out.decode()
89+
90+
if __name__=='__main__':
91+
# cd into the script directory.
92+
abspath = os.path.abspath(__file__)
93+
dname = os.path.dirname(abspath)
94+
os.chdir(dname)
95+
96+
with open("README.md","w") as f:
97+
f.write(readme.render(
98+
descriptions=get_descriptions(),
99+
similar_projects=get_similar_projects()
100+
))

‎python2.7/mt.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
#!/usr/bin/env python2
22

3+
__author__ = ['Brandon Amos <http://github.com/bamos>']
4+
__date__ = '2014.11.30'
5+
6+
"""
7+
This script implements the simple
8+
[multitail](https://pypi.python.org/pypi/multitail)
9+
example to tail multiple files and append the filename to the beginning
10+
of the output.
11+
"""
12+
313
import argparse
414
import multitail
515
import sys

‎python2.7/music-organizer.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
#!/usr/bin/env python2.7
2-
#
3-
# music-organizer.py
4-
# Brandon Amos <http://bamos.io/>
5-
# 2014.4.19
2+
3+
__author__ = ['Brandon Amos <http://github.com/bamos>']
4+
__date__ = '2014.04.19'
5+
6+
"""
7+
This script (music-organizer.py) organizes my music collection for
8+
iTunes and [mpv](http://mpv.io) using tag information.
9+
The directory structure is `<artist>/<track>`, where `<artist>` and `<track>`
10+
are lower case strings separated by dashes.
11+
"""
612

713
import argparse
814
import os
@@ -135,7 +141,6 @@ def artist(artistDir):
135141
sys.exit(-42)
136142
else:
137143
os.rename(fullPath, newFullPath)
138-
os.chmod(newFullPath, 0644)
139144
elif ext == ".pdf":
140145
pass
141146
else:
@@ -173,7 +178,6 @@ def song(filename):
173178
os.mkdir(neatArtist)
174179
newFullPath = os.path.join(neatArtist,neatTitle+ext)
175180
os.rename(filename, newFullPath)
176-
os.chmod(newFullPath, 0644)
177181

178182
def collection():
179183
for f in os.listdir("."):

‎python3/EvalExprTest.py‎

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
#!/usr/bin/env python3
2-
# EvalExpr.py
3-
# A module to evaluate a mathematical expression using Python's AST.
4-
#
5-
# Original by: J. Sebastian at `http://stackoverflow.com/questions/2371436`
6-
# Modifications by: Brandon Amos <http://bamos.github.io>
2+
3+
__author__ = ['J. Sebastian', 'Brandon Amos <http://github.com/bamos>']
4+
__date__ = '2013.08.01'
5+
6+
"""
7+
A module to evaluate a mathematical expression using Python's AST.
8+
9+
+ Original by: J. Sebastian at http://stackoverflow.com/questions/2371436.
10+
+ Modifications by: Brandon Amos <http://bamos.github.io>.
11+
12+
If you want a command-line expression evaluator, use
13+
[Russell91/pythonpy](https://github.com/Russell91/pythonpy).
14+
15+
16+
```
17+
$ eval-expr.py '(((4+6)*10)<<2)'
18+
(((4+6)*10)<<2) = 400
19+
```
20+
"""
721

822
import ast
923
import operator as op

‎python3/get-osx-wallpaper.py‎

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
#!/usr/bin/env python3
2-
#
3-
# This is a Python script that outputs the path of the current
4-
# OSX wallpaper.
5-
# This is helpful when the desktop wallpaper is randomized
6-
# across a large collection of pictures and you want to
7-
# delete the current wallpaper.
8-
#
9-
# 2015.03.25
10-
# Brandon Amos <http://github.com/bamos>
11-
#
12-
# --- Warning ---
13-
# + This approach doesn't work with multiple monitors.
14-
#
15-
# --- Tested On ---
16-
# + OSX Yosemite 10.10.2 with a single monitor on a MBP.
17-
#
18-
# --- Usage ---
19-
# Ensure `db_path` and `wallpaper_dir` are correctly set below.
20-
#
21-
# Assuming `get-osx-wallpaper.py` is on your path,
22-
# check the output with the following
23-
#
24-
# $ get-osx-wallpaper.py
25-
# /Users/bamos/Pictures/wallpaper/nature/496.jpg
26-
#
27-
# Please ensure this is correct before trying to remove it!
28-
#
29-
# This can be paired with other commands such as `open` or `rm`.
30-
# Run `killall Dock` to refresh the changes after removing the file.
31-
# Note that the dock will be restarted and all windows will be
32-
# unminimized.
33-
#
34-
# $ open $(get-osx-wallpaper.py)
35-
# $ rm $(get-osx-wallpaper.py) && killall Dock
36-
#
37-
# Example alias definitions for bash and zsh are available in
38-
# https://github.com/bamos/dotfiles/blob/master/.aliases:
39-
#
40-
# alias open-wallpaper='open $(get-osx-wallpaper.py)'
41-
# alias rm-wallpaper='rm $(get-osx-wallpaper.py) && killall Dock'
2+
3+
__author__ = ['Brandon Amos <http://github.com/bamos>']
4+
__date__ = '2015.03.25'
5+
6+
"""
7+
This is a Python script that outputs the path of the current
8+
OSX wallpaper.
9+
This is helpful when the desktop wallpaper is randomized
10+
across a large collection of pictures and you want to
11+
delete the current wallpaper.
12+
13+
14+
--- Warning ---
15+
+ This approach doesn't work with multiple monitors.
16+
17+
--- Tested On ---
18+
+ OSX Yosemite 10.10.2 with a single monitor on a MBP.
19+
20+
--- Usage ---
21+
Ensure `db_path` and `wallpaper_dir` are correctly set below.
22+
23+
Assuming `get-osx-wallpaper.py` is on your path,
24+
check the output with the following
25+
26+
$ get-osx-wallpaper.py
27+
/Users/bamos/Pictures/wallpaper/nature/496.jpg
28+
29+
Please ensure this is correct before trying to remove it!
30+
31+
This can be paired with other commands such as `open` or `rm`.
32+
Run `killall Dock` to refresh the changes after removing the file.
33+
Note that the dock will be restarted and all windows will be
34+
unminimized.
35+
36+
$ open $(get-osx-wallpaper.py)
37+
$ rm $(get-osx-wallpaper.py) && killall Dock
38+
39+
Example alias definitions for bash and zsh are available in
40+
https://github.com/bamos/dotfiles/blob/master/.aliases:
41+
42+
alias open-wallpaper='open $(get-osx-wallpaper.py)'
43+
alias rm-wallpaper='rm $(get-osx-wallpaper.py) && killall Dock'
44+
"""
4245

4346

4447
import sqlite3

‎python3/github-repo-summary.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env python3
2-
#
3-
# Brandon Amos <http://bamos.io>
4-
# 2014.11.02
2+
3+
__author__ = ['Brandon Amos <http://github.com/bamos>']
4+
__date__ = '2014.11.02'
5+
6+
"""
7+
Produces a Markdown table concisely summarizing a list of GitHub repositories.
8+
"""
59

610
from github import Github
711
import argparse

‎python3/link-checker.py‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#!/usr/bin/env python3
2-
#
3-
# link-checker.py
4-
# Script to be run by crontab to report broken links.
5-
#
6-
# Builds upon linkchecker (Ubuntu: sudo apt-get install linkchecker)
7-
# to hide warnings and to send a concise email if bad links are found.
8-
#
9-
# Brandon Amos <http://bamos.io>
10-
# 2014.02.06
2+
3+
__author__ = ['Brandon Amos <http://github.com/bamos>']
4+
__date__ = '2014.02.06'
5+
6+
"""
7+
Script to be run by crontab to report broken links.
8+
9+
Builds upon linkchecker (Ubuntu: sudo apt-get install linkchecker)
10+
to hide warnings and to send a concise email if bad links are found.
11+
12+
![Link checker screenshot](https://raw.githubusercontent.com/bamos/python-scripts/master/link-checker-screenshot.png?raw=true)
13+
"""
1114

1215
from subprocess import Popen,PIPE
1316

‎python3/merge-mutt-contacts.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env python3
2-
#
3-
# Brandon Amos <http://bamos.github.io>
4-
# 2015.01.08
2+
3+
__author__ = ['Brandon Amos <http://github.com/bamos>']
4+
__date__ = '2014.01.08'
5+
6+
"""
7+
Merges two mutt contact files.
8+
"""
59

610
import argparse
711
from collections import defaultdict

‎python3/merge-pdfs-printable.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env python3
2-
# 2014.10.17
32

4-
"""The printers in my office print a cover page before every job, and
3+
__author__ = ['Brandon Amos <http://github.com/bamos>']
4+
__date__ = '2014.10.17'
5+
6+
"""
7+
The printers in my office print a cover page before every job, and
58
I don't like printing many cover pages if I want to submit multiple
69
papers separately so that the papers don't overlap. This script will
710
merge PDF documents and insert blank pages so that the printed pages
@@ -30,8 +33,6 @@
3033
PS file.
3134
"""
3235

33-
__author__ = ['Brandon Amos <http://bamos.github.io>']
34-
3536
import argparse
3637
import os
3738
import re

0 commit comments

Comments
 (0)