Last active
August 29, 2015 14:13
-
-
Save anxiousmodernman/bbdf1941cc4ccd3317bf to your computer and use it in GitHub Desktop.
Budget script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/python3 | |
from datetime import datetime | |
import sys | |
""" | |
Pass the amount you've spent from the command line like this: | |
$ python3 money-left.py 2000 | |
or, if this script is on your PATH, like | |
$ money-left.py 2000 | |
""" | |
MONTHLY_INCOME = 3000 # replace this with your real income | |
DECEMBER = 12 | |
def get_remaining_days_in_month(): | |
"""Returns an object of type datetime.delta""" | |
today = datetime.now() | |
if today.month == DECEMBER: | |
next_month = datetime(today.year + 1, 1, 1) | |
else: | |
next_month = datetime(today.year, today.month + 1, 1) | |
delta = next_month - today | |
return delta | |
def main(spent): | |
remaining = MONTHLY_INCOME - float(spent) | |
delta = get_remaining_days_in_month() | |
per_day = remaining / delta.days | |
print('\nAssuming you make {:.2f} per month, you have {:.2f} remaining.'.format(MONTHLY_INCOME, remaining)) | |
print('You can spend ${:.2f} every day over the next {:.0f} days.\n'.format(per_day, delta.days)) | |
if __name__ == '__main__': | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment