Permalink
Browse files

small changes

  • Loading branch information...
1 parent f48b414 commit 5e0ac9fbbba3113262133e821ce51dea0de938d4 Jabba Laci committed Jan 8, 2012
Showing with 51 additions and 14 deletions.
  1. +3 −0 .gitignore
  2. +16 −4 02-extract.py
  3. +28 −0 03-combine-pieces.py
  4. +0 −3 03-combine-pieces.sh
  5. +3 −3 README
  6. +1 −0 issues.txt
  7. +0 −2 pieces/.gitignore
  8. +0 −2 result/.gitignore
View
@@ -0,0 +1,3 @@
+!.gitignore
+gimp/
+python/
View
@@ -2,14 +2,26 @@
import os
import sys
+import errno
# extract.py
-if len(sys.argv) == 1:
- print "Usage: %s series.csv" % sys.argv[0]
+# one parameter is required and that parameter must be a .csv file
+if (len(sys.argv) == 1) or (os.path.splitext(sys.argv[1])[1] != '.csv'):
+ print "Usage: {prg} series.csv".format(prg=sys.argv[0])
+ print "Tip: the passed parameter file must have .csv extension."
sys.exit()
-# else, if a parameter was passed
+# else, if a .csv file was passed
+
+topic = os.path.splitext(sys.argv[1])[0] # ex. gimp.csv => gimp
+
+try:
+ os.makedirs("{topic}/result".format(topic=topic))
+except OSError as exc:
+ if exc.errno == errno.EEXIST:
+ pass
+ else: raise
f1 = open(sys.argv[1], 'r')
@@ -19,7 +31,7 @@
# else
line = line.rstrip('\n')
(issue, start_page, end_page) = line.split(';')
- command = "pdftk issues/issue%s_en.pdf cat %s-%s output pieces/%s-%s.pdf" % (issue, start_page, end_page, issue, os.path.splitext(sys.argv[1])[0] )
+ command = "pdftk issues/issue{n}_en.pdf cat {start}-{end} output {topic}/{issue}-{topic}.pdf".format(n=issue, start=start_page, end=end_page, issue=issue, topic=topic)
print command
os.system(command)
View
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+import os
+import sys
+
+# combine.py
+
+# one parameter is required and that parameter must be a .csv file
+if (len(sys.argv) == 1) or (os.path.splitext(sys.argv[1])[1] != '.csv'):
+ print "Usage: {prg} series.csv".format(prg=sys.argv[0])
+ print "Tip: the passed parameter file must have .csv extension."
+ sys.exit()
+
+# else, if a .csv file was passed
+
+topic = os.path.splitext(sys.argv[1])[0] # ex. gimp.csv => gimp
+
+dest = "{topic}/result".format(topic=topic)
+if not os.path.exists(dest):
+ print "Error: {dest} doesn't exist.".format(dest=dest)
+ print "Tip: did you execute the 2nd script?"
+ sys.exit()
+
+# else, if the destination directory is there
+
+command = "pdftk {topic}/*.pdf cat output {topic}/result/all.pdf".format(topic=topic)
+print command
+os.system(command)
@@ -1,3 +0,0 @@
-#!/usr/bin/env bash
-
-pdftk pieces/*.pdf cat output result/all.pdf
View
@@ -2,7 +2,7 @@ Full-Circle-Magazine-Series
===========================
Author: Laszlo Szathmary (jabba.laci@gmail.com)
-Last update: 2011-08-27 (yyyy-mm-dd)
+Last update: 2012-01-08 (yyyy-mm-dd)
Version: 0.2
Home page: https://ubuntuincident.wordpress.com/2011/02/21/python-tutorials-of-full-circle-magazine-in-a-single-pdf/
@@ -27,8 +27,8 @@ Usage:
You can write your own series.csv file (ex.: gimp.csv) to extract
a different series.
-./03-combine-pieces.sh
+./03-combine-pieces.py python.csv
Combine the pieces together in a single PDF. Location of the result:
- result/all.pdf.
+ python/result/all.pdf.
If you combine the pieces with Adobe Acrobat Pro, the size of the
resulting file will be very small. Pdftk produces a much larger file.
View
@@ -54,3 +54,4 @@ http://dl.fullcirclemagazine.org/issue52_en.pdf
http://dl.fullcirclemagazine.org/issue53_en.pdf
http://dl.fullcirclemagazine.org/issue54_en.pdf
http://dl.fullcirclemagazine.org/issue55_en.pdf
+http://dl.fullcirclemagazine.org/issue56_en.pdf
View
@@ -1,2 +0,0 @@
-*
-!.gitignore
View
@@ -1,2 +0,0 @@
-*
-!.gitignore

0 comments on commit 5e0ac9f

Please sign in to comment.