Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 1 addition & 34 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
__pycache__

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject
*.html
313 changes: 210 additions & 103 deletions examples/paycheckProcess.py
Original file line number Diff line number Diff line change
@@ -1,118 +1,225 @@
#!/usr/bin/env python2

from datetime import date, timedelta
from dateutil.relativedelta import relativedelta
from bs4 import BeautifulSoup
import re
from getpass import getpass

import os
import sys
sys.path.append("../")
from paycheckrecords import *

def checkRowForAll(row):
for col in row.findAll('td'):
if "Federal Income Tax" in str(col):
return True
if "Social Security" in str(col):
return True
if "Medicare" in str(col):
return True
if "NY Income Tax" in str(col):
return True
if "Cell Phone" in str(col):
return True
if "Deductions" in str(col):
return True
if "Taxes" in str(col):
return True
return False
for col in row.findAll('td'):
if "Federal Income Tax" in str(col):
return True
if "Social Security" in str(col):
return True
if "Medicare" in str(col):
return True
if "NY Income Tax" in str(col):
return True
if "Cell Phone" in str(col):
return True
if "Deductions" in str(col):
return True
if "Taxes" in str(col):
return True

return False

def blackOut(html):
soup = BeautifulSoup(html)

#blackout net pay
tmp = soup.findAll('u')
for tag in tmp:
if "Net Pay" in str(tag.parent):
tag["style"] = "background-color:black; -webkit-print-color-adjust: exact;"
tableList = ["paystub_pay_tbl", "paystub_ee_taxes_tbl", "paystub_summary_tbl"]

#black out all
for curTable in tableList:
tmpTable = soup.find("table", {"id": curTable})
allrows = tmpTable.findAll('tr')
for row in allrows:
if checkRowForAll(row):
for col in row.findAll('td'):
if '.' in str(col):
col["style"] = "background-color:black; -webkit-print-color-adjust: exact;"



#black out netthispay
elem = soup.find(text=re.compile('.*Net This Check:.*'))
elem = elem.findNext('td')
elem["style"] = "background-color:black; -webkit-print-color-adjust: exact;"

#black out account
elem = soup.find(text=re.compile('.*Acct#.*'))

nelem = elem.findNext('td')
nelem["style"] = "background-color:black; -webkit-print-color-adjust: exact;"

contents = elem.string
contentsList = contents.split("#")
newcontent = contentsList[0] + "#<span style = \"background-color:black; -webkit-print-color-adjust: exact;\">"
contentsList = contentsList[1].split(":")
newcontent = newcontent + contentsList[0] + "</span>:" + contentsList[1]
elem.replaceWith(newcontent)

return str(soup.prettify(formatter=None))
soup = BeautifulSoup(html, "lxml")

#blackout net pay
tmp = soup.findAll('u')
for tag in tmp:
if "Net Pay" in str(tag.parent):
tag["style"] = "background-color:black; -webkit-print-color-adjust: exact;"
tableList = ["paystub_pay_tbl", "paystub_ee_taxes_tbl", "paystub_summary_tbl"]

#black out all
for curTable in tableList:
tmpTable = soup.find("table", {"id": curTable})
allrows = tmpTable.findAll('tr')
for row in allrows:
if checkRowForAll(row):
for col in row.findAll('td'):
if '.' in str(col):
col["style"] = "background-color:black; -webkit-print-color-adjust: exact;"



#black out netthispay
elem = soup.find(text=re.compile('.*Net This Check:.*'))
elem = elem.findNext('td')
elem["style"] = "background-color:black; -webkit-print-color-adjust: exact;"

#black out account
elem = soup.find(text=re.compile('.*Acct#.*'))

nelem = elem.findNext('td')
nelem["style"] = "background-color:black; -webkit-print-color-adjust: exact;"

contents = elem.string
contentsList = contents.split("#")
newcontent = contentsList[0] + "#<span style = \"background-color:black; -webkit-print-color-adjust: exact;\">"
contentsList = contentsList[1].split(":")
newcontent = newcontent + contentsList[0] + "</span>:" + contentsList[1]
elem.replaceWith(newcontent)

return str(soup.prettify(formatter=None))

def printSimpleSummary( stubs ):
gross = 0.0
totalnet = 0.0

print("")
print("QUICK SUMMARY:")
print("")

print("----------------------------------------------")
print(('{: <20} {: >12} {: >12}'.format( "Date",
"Total Pay",
"Net Pay" )))
print("----------------------------------------------")
for stub in stubs:
print(('{: <20} {: >12} {: >12}'.format( stub.PayDate.strftime("%Y-%m-%d"),
stub.TotalPay,
stub.NetPay )))
gross = gross + stub.TotalPay
totalnet = totalnet + stub.NetPay

print("----------------------------------------------")
print(('{: <20} {: >12} {: >12}'.format( "",
str(gross),
str(totalnet) )))
print("")

def printDetailedSummary( stubs ):
summary = {}
for stub in stubs:
for f in stub.StubDetails:
if f['name'] in summary:
summary[f['name']]['hours'] += f['hours']
summary[f['name']]['rate'] += f['rate']
summary[f['name']]['current'] += f['current']
else:
summary[f['name']] = { 'hours' : f['hours'],
'rate' : f['rate'],
'current' : f['current'] }

print("")
print("DETAILED TOTALS:")
print("")

print("-----------------------------------------------------------")
print(('{: <20} {: >12} {: >12} {: >12}'.format( "Field",
"Total Hours",
"Total Rate",
"Total" )))
print("-----------------------------------------------------------")
for s in summary:
print(('{: <20} {: >12.2f} {: >12.2f} {: >12.2f}'.format( s,
summary[s]['hours'],
summary[s]['rate'],
summary[s]['current'] )))
print("")


def savePayStubs( stubs, redact=False ):
for stub in stubs:
filename = "paystub-" + stub.PayDate.strftime("%Y-%m-%d")

if os.path.isfile(filename + ".html"):
i = 1
while os.path.isfile(filename + "_" + str(i) + ".html"):
i += 1
if i == 100:
print("There seem to be a lot of duplicate files? Aborting.")
return -1
filename += '_' + str(i)

out = open(filename + ".html", "w")
out.write(stub.HTML)
out.close()

if redact:
out = open(filename + "_redacted.html", "w")
out.write(blackOut(stub.HTML))
out.close()

def yesno( x ):
while True:
resp = input(x)
if( resp.lower() == 'y' ):
return True
elif( resp.lower() == 'n' ):
return False
else:
print(" Invalid response.")

def get_date( x, fmt='%m/%d/%Y' ):
while True:
try:
#resp = eval(input(x)) or datetime.today().strftime(fmt)
resp = input(x) or datetime.today().strftime(fmt)
return datetime.strptime(resp, fmt)
except ValueError:
print(" Invalid date or date format provided.")

def main():

_day = int(input("Day:"))
username = raw_input("Username:")
password = getpass("Password:")

paycheckinst = paycheckrecords(username, password)
try:

now = date.today()

if now.day > _day:
startdate = now.replace(day=_day+1)
enddate = startdate + timedelta(days=32)
enddate = enddate.replace(day = _day)

else:


enddate = now.replace(day=_day)
tmpdate = now.replace(day=1) - timedelta(days=1)
startdate = tmpdate.replace(day=_day+1)



ret = paycheckinst.getPayStubsInRange(startdate, enddate)
gross = 0.0
for stub in ret:
print "Date: ", stub.PayDate
print "Total Pay: ", stub.TotalPay
print "Net Pay: ", stub.NetPay
print ""
gross = gross + stub.TotalPay
filename = "paystub " + stub.PayDate.strftime("%m-%d-%Y")
out = open(filename + ".html", "w")
out.write(stub.HTML)
out.close()

out = open(filename + "(blacked out).html", "w")
out.write(blackOut(stub.HTML))
out.close()
print "Gross: " + str(gross)
finally:
paycheckinst.close()


print("")
print("Print a summary of all pay stubs between the given dates.")
print("Optionally save off the pay stubs and redacted pay stubs.")
print("")

while True:
startdate = get_date("Start date (MM/DD/YYYY): ", '%m/%d/%Y')
enddate = get_date("End date (MM/DD/YYYY): ", '%m/%d/%Y')
if( startdate <= enddate ):
break
else:
print(" Invalid date range. Start date must be before or equal to end date.")

savestubs = yesno("Save pay stubs? [Y/n] ")
if( savestubs ):
saveredacted = yesno("Save redacted pay stubs? [Y/n] ")
if( saveredacted ):
# Deleting the sensitive information is an exercise for the reader ...
print(" WARNING: redacted pay stubs are intended to be printed. Although")
print(" it is blacked out, the sensitive information is still")
print(" present in the document.")
saveredacted = yesno(" Do you acknowledge and accept the above warning? [Y/n] ")

print("PaycheckRecords.com Credentials:")

while True:
username = input(" Username: ")
if( username != "" ):
break

while True:
password = getpass(" Password: ")
if( password != "" ):
break

print("")

paycheckinst = paycheckrecords(username, password)

try:
stubs = paycheckinst.getPayStubsInRange(startdate, enddate)

printSimpleSummary( stubs )
printDetailedSummary( stubs )

if savestubs:
savePayStubs( stubs, saveredacted )

finally:
paycheckinst.close()

main()
5 changes: 2 additions & 3 deletions paycheckrecords/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import paystub
from paycheckrecords import *

from . import paystub
from .paycheckrecords import *
Loading