Advertisement
yloplopy

Python 3

Oct 9th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. from LetterHelperFunctions import *
  2.  
  3. """
  4. This is a script that reads a specfied CSV to help make customized boiler plate letter to people or things.
  5. To Run:
  6. [user@machine ]$ python LetterWriteMain.py AddressFile.txt
  7. """
  8.  
  9. #================================
  10. #Read in command line arguments
  11. #================================
  12.  
  13. if len(sys.argv) != 2:
  14. print "To Run: python LetterWriteMain.py AddressFile.txt"
  15. else:
  16. print "Using info from file", str(sys.argv[1])
  17. dataFile = str(sys.argv[1])
  18.  
  19. #================================
  20. #Open File(s)
  21. #================================
  22.  
  23. AddressData = open(dataFile, "r")
  24.  
  25. #================================
  26. #Read Data from File Line by Line
  27. #================================
  28.  
  29. print "Reading File............"
  30.  
  31. AddressList = []
  32.  
  33. for line in AddressData.readlines():
  34. First, Last, add, Place = map(str, line.split(','))
  35. CurrentAddress = Addresses(First,Last,add,Place)
  36. #Self Check
  37. #CurrentAddress.dumpAddress()
  38. AddressList.append(CurrentAddress)
  39.  
  40. #================================
  41. #Write Letters to People
  42. #================================
  43.  
  44. for i in range(len(AddressList)):
  45. Letter = DocumentText(AddressList[i])
  46. Letter.WriteLetter()
  47.  
  48.  
  49. ----------------------------------------------
  50.  
  51. import sys #This is for System Interaction, (Import command line arguments)
  52. import os #Allows for Operating System Interaction
  53. from string import whitespace
  54. import math
  55.  
  56. """
  57. This are my Helper Functions and Classes for the LetterWriteMain.py Script
  58. """
  59.  
  60. #=======================
  61. #Define a Class
  62. #=======================
  63.  
  64. class Addresses:
  65. def __init__(self, First, Last, Address, Place):
  66. self.First = First
  67. self.Last = Last
  68. self.Address = Address
  69. self.Place = Place
  70. def dumpAddress(self):
  71. #This is so I can look at what I have in my contents.
  72. print "Address Information:"
  73. print " ", self.First, self.Last
  74. print " ", self.Address
  75. print " ", self.Place
  76.  
  77. class DocumentText:
  78. def __init__(self, sendTo):
  79. self.sendTo = sendTo
  80.  
  81. self.header = ("\\documentclass[12pt]{article} \n"
  82. +"\\usepackage{geometry} \n"
  83. +"\\begin{document} \n"
  84. +"\\thispagestyle{empty} \n\n"
  85. )
  86. self.myAddress = "My Address \n\n \\vskip.5in \n\n"
  87. self.toAddress = (self.sendTo.First + " " + self.sendTo.Last + "\n\n"
  88. + self.sendTo.Address + " \n\n"
  89. + self.sendTo.Place + " \n\n"
  90. )
  91. self.date = "\\vskip.5in \n \\today \n\n \\vskip.5in \n\n"
  92. self.greeting = "Dear " + self.sendTo.First + " " + self.sendTo.Last + ", \n\n \vskip.5in \n\n"
  93. self.body = "I'm very happy about all the awesome things you do. Thanks for being so dope af."
  94. self.signature = "\\vskip.5in \hskip3.5in Love, \n\n \\hskip3.5in Nick <3"
  95. self.footer = "\\end{document}\n"
  96.  
  97. def WriteLetter(self):
  98. LetterOutName = str(self.sendTo.Last.lstrip(' ')) + ".tex"
  99. LetterFile = open(LetterOutName, "w")
  100. LetterFile.write(self.header)
  101. LetterFile.write(self.myAddress)
  102. LetterFile.write(self.toAddress)
  103. LetterFile.write(self.date)
  104. LetterFile.write(self.greeting)
  105. LetterFile.write(self.body)
  106. LetterFile.write(self.signature)
  107. LetterFile.write(self.footer)
  108. LetterFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement