Skip to content

Instantly share code, notes, and snippets.

@andrewbt
Last active January 30, 2021 19:53
Show Gist options
  • Save andrewbt/012f171a3d492618173a99cec240440b to your computer and use it in GitHub Desktop.
Save andrewbt/012f171a3d492618173a99cec240440b to your computer and use it in GitHub Desktop.
I get paid a base salary plus variable commissions. The paystubs come into Pocketsmith (love it!) as a combined net-value (after taxes), but I want to track them separately. My paystubs don't tell me what portion is "net commission" and I got tired of using my calculator. This little command-line Python3 calculator does the math for me now!
import subprocess
#from https://stackoverflow.com/questions/1825692/can-python-send-text-to-the-mac-clipboard
def write_to_clipboard(output):
process = subprocess.Popen(
'pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE)
process.communicate(output.encode('utf-8'))
#get inputs
gcomm = float(input("Enter gross commission only: "))
gpay = float(input("Enter gross pay (including commissions): "))
npay = float(input("Enter net pay: "))
#calculate
ncomm = (gcomm / gpay) * npay
nsal = npay - ncomm
#display
print("\nNet salary is {:.2f}\n".format(nsal))
print("Net commission is {:.2f}".format(ncomm))
#copy to clipboard for Pocketsmith!
nsal_string = "{:.2f}".format(nsal)
write_to_clipboard(nsal_string)
print("\nThe net salary has been copied to your clipboard!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment