Reworked some of the mailing logic and what I believe to be current postage rates. Seems like even just pulling the component price is not fool proof.

This commit is contained in:
2020-04-15 12:25:32 -04:00
parent cc44202d20
commit f7236c7164

21
main.py
View File

@@ -3,14 +3,15 @@ from itertools import groupby
import fitz
import csv
doc = fitz.open("std.pdf")
# doc = fitz.open("flyers.pdf")
# doc = fitz.open("poster.pdf")
####### IMPORT MAILING RATE SECTION #########
psFCrate = '.47'
psSCrate = '.25'
psFCcutoff = '500'
psFCrate = '.55'
psSCrate = '.44'
psFCcutoff = '200'
count = doc.pageCount
currentPage = 0
@@ -54,6 +55,7 @@ while currentPage < count:
Totalrect = (559.75, 551.71728515625, 584.52099609375, 560.7664794921875) #compontent price not total price
Mailingrect = (555.25, 172.9172821044922, 584.5245971679688, 181.9665069580078) #component price for mailing component
# Find the total job cost on each page
total = [w for w in words if fitz.Rect(w[:4]).intersects(Totalrect)]
total.sort(key=itemgetter(3, 0))
@@ -80,9 +82,9 @@ while currentPage < count:
mailPerPeice = round(float(totalMail.strip('$'))/currentBreak,4)
if includePostage is True:
if currentBreak < int(psFCcutoff):
mailPerPeice = mailPerPeice + float(psFCrate)
mailPerPeice = round(mailPerPeice + float(psFCrate),4)
elif currentBreak >= int(psFCcutoff):
mailPerPeice = mailPerPeice + float(psSCrate)
mailPerPeice = round(mailPerPeice + float(psSCrate),4)
mailrow.append('\"' + str(mailPerPeice) + '\"')
else:
exit()
@@ -90,8 +92,10 @@ while currentPage < count:
currentBreak = currentBreak+breaks
else:
currentBreak = (currentBreak + breaks)-1
currentPage = currentPage+1
if checkMail is True and currentPage == 1:
currentBreak = currentBreak - 1
currentPage = currentPage+1
# Add the weight sections after all the qty breaks
qtyrow.append('Unit Weight')
qtyrow.append('Tare Weight')
@@ -101,6 +105,11 @@ costrow.append('\"'+str(.5039)+'\"')
costrow.append('\"'+str(48)+'\"')
costrow.append('\"'+str(400)+'\"')
if checkMail is True:
mailrow.append('\"0\"')
mailrow.append('\"0\"')
mailrow.append('\"0\"')
# csv.register_dialect('unixpwd', delimiter=',', quoting=csv.QUOTE_NONE)
with open('pricetable.csv', 'w', newline='') as f:
writer = csv.writer(f, quoting=csv.QUOTE_NONE, quotechar="")