Skip to content

Commit 641ee41

Browse files
committed
Merge branch 'master' of github.com:bamos/python-scripts
2 parents ebf8a38 + 4d93d59 commit 641ee41

4 files changed

Lines changed: 68 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ The directory structure is `<artist>/<track>`, where `<artist>` and `<track>`
2727
are lower case strings separated by dashes.
2828
See the [blog post][music-organizer-post] for a more detailed overview.
2929

30+
## mt.py
31+
Implements the simple [multitail](https://pypi.python.org/pypi/multitail)
32+
example to tail multiple files and append the filename to the beginning
33+
of the output.
34+
3035
# Python 3
3136
## EvalExpr.py
3237
A module to evaluate a mathematical expression using Python's AST.
@@ -170,6 +175,54 @@ u - uniform
170175
b - bravo
171176
```
172177

178+
## rank-writing.py
179+
`rank-writing.py` ranks the writing quality of my
180+
blog's Markdown posts and my project's Markdown README files.
181+
See the [blog post](http://bamos.github.io/2014/12/12/rank-writing/)
182+
for further details.
183+
184+
The following programs should be on your `PATH`:
185+
+ [aspell](http://aspell.net/)
186+
+ [write-good](https://github.com/btford/write-good)
187+
+ [diction](https://www.gnu.org/software/diction/)
188+
189+
190+
```
191+
$ rank-writing.py *.md
192+
193+
=== 2013-05-03-scraping-tables-python.md ===
194+
Total: 53
195+
├── aspell: 34
196+
├── diction: 0
197+
└── write-good: 19
198+
199+
=== 2014-09-08-nbd-android.md ===
200+
Total: 45
201+
├── aspell: 31
202+
├── diction: 0
203+
└── write-good: 14
204+
205+
...
206+
207+
=== 2013-03-11-mirroring-android.md ===
208+
Total: 1
209+
├── aspell: 1
210+
├── diction: 0
211+
└── write-good: 0
212+
213+
=== 2014-10-26-analyzing-writing-in-latex.md ===
214+
Total: 0
215+
├── aspell: 0
216+
├── diction: 0
217+
└── write-good: 0
218+
219+
=== 2013-04-16-pdf-from-plaintext.md ===
220+
Total: 0
221+
├── aspell: 0
222+
├── diction: 0
223+
└── write-good: 0
224+
```
225+
173226
## word-counter.py
174227
Count work frequencies within a file.
175228

‎python2.7/music-organizer.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def toNeat(s):
6464
s = re.sub("^-*", "", s)
6565
s = re.sub("-*$", "", s)
6666

67-
# Ensure the string is only alphanumeric with '-' and '+'.
68-
search = re.search("[^0-9a-z\-\+]", s)
67+
# Ensure the string is only alphanumeric with '-', '+', and '='.
68+
search = re.search("[^0-9a-z\-\+\=]", s)
6969
if search:
7070
print("Error: Unrecognized character in '" + s + "'")
7171
sys.exit(-42)
@@ -151,6 +151,9 @@ def artist(artistDir):
151151
shutil.rmtree(os.path.join(artistDir,d),ignore_errors=True)
152152

153153
def song(filename):
154+
if filename[0] == '.':
155+
print("Ignoring dotfile: '{}'".format(filename))
156+
return
154157
print("Organizing song '" + filename + "'.")
155158
ext = os.path.splitext(filename)[1]
156159
try:

‎python3/github-repo-summary.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ def sanitize_for_md(s):
1818
s = s.replace("*","\*")
1919
return s
2020

21-
print(
22-
"Generated on {}, see the Markdown source of this file for more details.\n".format(
23-
time.strftime("%Y-%m-%d")
24-
)
25-
)
21+
#print("Generated on {}.\n".format(time.strftime("%Y-%m-%d")))
2622
print("Name | Stargazers | Description")
2723
print("|".join(["----"]*3))
2824
for r_name in sorted(args.repos, key=lambda v: v.upper()):

‎python3/rank-writing.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import argparse
44
import re
55
from subprocess import Popen,PIPE
6+
import shutil
7+
import sys
68

79
parser = argparse.ArgumentParser()
810
parser.add_argument('--aspell',action='store_true')
@@ -20,6 +22,11 @@
2022
if args.diction: programs.append("diction")
2123
if args.write_good: programs.append("write-good")
2224

25+
for program in programs:
26+
if not shutil.which(program):
27+
print("Error: '{}' not found on PATH. Please install.".format(program))
28+
sys.exit(-1)
29+
2330
def call(cmd,in_f=None):
2431
if in_f:
2532
with open(in_f,'r') as f:
@@ -35,15 +42,15 @@ def getNumSuggestions(program,f_name):
3542
if program == "write-good":
3643
out = call(["write-good",f_name])
3744
return out.count("-------------")
38-
elif program == "aspell":
45+
elif program == "diction":
3946
out = call(["diction","--suggest",f_name])
4047
r = re.search("(\S*) phrases? in (\S*) sentences? found.",out)
4148
if r:
4249
if r.group(1) == "No":
4350
return 0
4451
else:
4552
return int(r.group(1))
46-
elif program == "diction":
53+
elif program == "aspell":
4754
out = call(["aspell","list"],in_f=f_name)
4855
return len(out.split())
4956
else:

0 commit comments

Comments
 (0)