Skip to content

Commit a24dde1

Browse files
committed
Merge branch 'master' of github.com:bamos/python-scripts
2 parents 632c958 + 4f4b30d commit a24dde1

3 files changed

Lines changed: 39 additions & 13 deletions

File tree

‎README.md‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ of the output.
3636
## EvalExpr.py
3737
A module to evaluate a mathematical expression using Python's AST.
3838
Tests are located in `EvalExprTest.py`.
39-
See the [blog post][eval-post] for a more detailed overview.
4039

4140
```
4241
$ EvalExpr.py '(((4+6)*10)<<2)'
@@ -45,7 +44,6 @@ $ EvalExpr.py '(((4+6)*10)<<2)'
4544

4645
## github-repo-summary.py
4746
Produces a Markdown table concisely summarizing a list of GitHub repositories.
48-
See the [blog post][repo-summary-post] for a more detailed overview.
4947
The following is an example from my [bamos/cv][cv] project.
5048

5149
```
@@ -110,7 +108,6 @@ Name | Stargazers | Description
110108
## link-checker.py
111109
Builds upon linkchecker to hide warnings and to send a concise email
112110
if bad links are found.
113-
See the [blog post][link-checker-post] for a more detailed overview.
114111

115112
![Link checker screenshot](https://raw.githubusercontent.com/bamos/python-scripts/master/link-checker-screenshot.png?raw=true)
116113

@@ -163,8 +160,6 @@ b - bravo
163160
## rank-writing.py
164161
`rank-writing.py` ranks the writing quality of my
165162
blog's Markdown posts and my project's Markdown README files.
166-
See the [blog post](http://bamos.github.io/2014/12/12/rank-writing/)
167-
for further details.
168163

169164
The following programs should be on your `PATH`:
170165
+ [aspell](http://aspell.net/)
@@ -266,10 +261,7 @@ $ word-counter.py README.md
266261

267262

268263
[country-post]: http://bamos.github.io/2013/05/03/scraping-tables-python/
269-
[eval-post]: http://bamos.github.io/2013/08/07/python-expression-evaluator/
270-
[link-checker-post]: http://bamos.github.io/2014/02/06/link-checker-crontab/
271264
[music-organizer-post]: http://bamos.github.io/2014/07/05/music-organizer/
272-
[repo-summary-post]: http://bamos.github.io/2014/11/02/github-repo-summary/
273265

274266
[mpv]: http://mpv.io/
275267
[pip]: http://pip.readthedocs.org/en/latest/

‎python3/link-checker.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python3
1+
#!/usr/bin/env python3
22
#
33
# link-checker.py
44
# Script to be run by crontab to report broken links.

‎python3/merge-pdfs-printable.py‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
#!/usr/bin/env python3
2-
#
3-
# Brandon Amos <http://bamos.github.io>
42
# 2014.10.17
53

4+
"""The printers in my office print a cover page before every job, and
5+
I don't like printing many cover pages if I want to submit multiple
6+
papers separately so that the papers don't overlap. This script will
7+
merge PDF documents and insert blank pages so that the printed pages
8+
won't overlap documents. The modulo option is helpful to print 2 PDF
9+
pages per physical page side.
10+
11+
The script uses PyPDF2 to merge the documents and to extract the
12+
number of pages in the input documents and ghostscript to create a
13+
blank PDF page.
14+
15+
$ merge-pdfs-printable.py a.pdf b.pdf c.pdf --modulo 4
16+
a.pdf
17+
+ Pages: 6
18+
+ Added 2 blank pages.
19+
b.pdf
20+
+ Pages: 13
21+
+ Added 3 blank pages.
22+
c.pdf
23+
+ Pages: 13
24+
+ Added 3 blank pages.
25+
Merged output is in '/tmp/tmpm2n5g0mh-merge.pdf'.
26+
27+
Note: Some of my decrypted PDF documents have resulted in
28+
PyPDF2.utils.PdfReadError: file has not been decrypted. My current
29+
workaround solution is to run pdf2ps on the PDF and then ps2pdf on the
30+
PS file.
31+
"""
32+
33+
__author__ = ['Brandon Amos <http://bamos.github.io>']
34+
635
import argparse
736
import os
837
import re
@@ -39,8 +68,13 @@ def get_pages_in_pdf(f_path):
3968
def merge_pdfs(f_names):
4069
merger = PdfFileMerger()
4170
fps = [open(f,'rb') for f in f_names]
42-
[merger.append(f) for f in fps]
43-
out_file = tempfile.mktemp("-merge.pdf")
71+
for f in fps:
72+
try:
73+
merger.append(f)
74+
except:
75+
print("Error merging {}".format(f))
76+
raise
77+
out_file = "merged.pdf" #tempfile.mktemp("-merge.pdf")
4478
with open(out_file,'wb') as f:
4579
merger.write(f)
4680
[f.close() for f in fps]

0 commit comments

Comments
 (0)