Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from LetterHelperFunctions import *
- """
- This is a script that reads a specfied CSV to help make customized boiler plate letter to people or things.
- To Run:
- [user@machine ]$ python LetterWriteMain.py AddressFile.txt
- """
- #================================
- #Read in command line arguments
- #================================
- if len(sys.argv) != 2:
- print "To Run: python LetterWriteMain.py AddressFile.txt"
- else:
- print "Using info from file", str(sys.argv[1])
- dataFile = str(sys.argv[1])
- #================================
- #Open File(s)
- #================================
- AddressData = open(dataFile, "r")
- #================================
- #Read Data from File Line by Line
- #================================
- print "Reading File............"
- AddressList = []
- for line in AddressData.readlines():
- First, Last, add, Place = map(str, line.split(','))
- CurrentAddress = Addresses(First,Last,add,Place)
- #Self Check
- #CurrentAddress.dumpAddress()
- AddressList.append(CurrentAddress)
- #================================
- #Write Letters to People
- #================================
- for i in range(len(AddressList)):
- Letter = DocumentText(AddressList[i])
- Letter.WriteLetter()
- ----------------------------------------------
- import sys #This is for System Interaction, (Import command line arguments)
- import os #Allows for Operating System Interaction
- from string import whitespace
- import math
- """
- This are my Helper Functions and Classes for the LetterWriteMain.py Script
- """
- #=======================
- #Define a Class
- #=======================
- class Addresses:
- def __init__(self, First, Last, Address, Place):
- self.First = First
- self.Last = Last
- self.Address = Address
- self.Place = Place
- def dumpAddress(self):
- #This is so I can look at what I have in my contents.
- print "Address Information:"
- print " ", self.First, self.Last
- print " ", self.Address
- print " ", self.Place
- class DocumentText:
- def __init__(self, sendTo):
- self.sendTo = sendTo
- self.header = ("\\documentclass[12pt]{article} \n"
- +"\\usepackage{geometry} \n"
- +"\\begin{document} \n"
- +"\\thispagestyle{empty} \n\n"
- )
- self.myAddress = "My Address \n\n \\vskip.5in \n\n"
- self.toAddress = (self.sendTo.First + " " + self.sendTo.Last + "\n\n"
- + self.sendTo.Address + " \n\n"
- + self.sendTo.Place + " \n\n"
- )
- self.date = "\\vskip.5in \n \\today \n\n \\vskip.5in \n\n"
- self.greeting = "Dear " + self.sendTo.First + " " + self.sendTo.Last + ", \n\n \vskip.5in \n\n"
- self.body = "I'm very happy about all the awesome things you do. Thanks for being so dope af."
- self.signature = "\\vskip.5in \hskip3.5in Love, \n\n \\hskip3.5in Nick <3"
- self.footer = "\\end{document}\n"
- def WriteLetter(self):
- LetterOutName = str(self.sendTo.Last.lstrip(' ')) + ".tex"
- LetterFile = open(LetterOutName, "w")
- LetterFile.write(self.header)
- LetterFile.write(self.myAddress)
- LetterFile.write(self.toAddress)
- LetterFile.write(self.date)
- LetterFile.write(self.greeting)
- LetterFile.write(self.body)
- LetterFile.write(self.signature)
- LetterFile.write(self.footer)
- LetterFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement