#!/usr/bin/python #Parse the input text file and add cards to a cardpage document. #Input text file has two types of line: # #Variable setting: # # edition = # author = # type = # background = # panel = # back = # #Card definition: # # * # #(the first text field is the card value, the text after the '*', if present, # is the card comment). # #After an edition, author, or type field is set, it is used for all card #definitions parsed until another line changes its value. All blank lines are #ignored, as are lines starting with a # character. # #No check is made for field lengths, so keep them reasonable, or the cards #will get garbled. # # Andrew Williams import sys import os import string import card import cardpage if len(sys.argv)<>2: print "Usage: "+argv[0]+" filename" print " --> filename.pdf as output" infile=open(sys.argv[1], 'r') outfile=open(os.path.basename(sys.argv[1])+'.pdf', 'w') cards=cardpage.Document(cardheight=228.47, cardwidth=144.28, hgap=24.1, vgap=13.61, minborder=28, portrait=0) #80.6mm by 50.9mm cards, 8.4mm and 4.8mm gaps, 1cm min border, landscape #ie, Avery business card paper format. edition='None' author='Anonymous' type='Misc' value='' comment='' for line in infile.readlines(): line=string.strip(line) if line and line[0]<>'#': #ignore blank lines and comments lpair=string.split(line,'=') if len(lpair)==2: #Is this line defining a variable? field=string.lower(string.strip(lpair[0])) if field=='edition': edition=string.strip(lpair[1]) elif field=='author': author=string.strip(lpair[1]) elif field=='type': type=string.strip(lpair[1]) elif field=='background': background=string.strip(lpair[1]) elif field=='panel': panel=string.strip(lpair[1]) else: print "Bad line: ",line else: #If not, it's defining a card... lpair=string.split(line,'*') if len(lpair)==2: #Do we have a comment field? value=string.strip(lpair[0]) comment=string.strip(lpair[1]) else: value=string.strip(line) comment='' c=card.Card(edition=edition, author=author, type=type, value=value, comment=comment, background=background, panel=panel) cards.addcard(c) cards.save(outfile) #Create the PDF output file. infile.close() outfile.close()