Created
October 20, 2015 11:25
-
-
Save mnagy/874ec46ef1593d332293 to your computer and use it in GitHub Desktop.
Script to tell me how much I can spend untill the next payday
This file contains 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 | |
import sys | |
import datetime | |
def get_money(): | |
try: | |
return int(sys.argv[1]) | |
except (ValueError, IndexError): | |
print("Usage: {0} <money>".format(sys.argv[0])) | |
sys.exit(1) | |
def next_payday(today): | |
try: | |
return datetime.date(today.year, today.month+1, 15) | |
except ValueError: | |
return datetime.date(today.year+1, 1, 15) | |
def days_until_payday(): | |
today = datetime.date.today() | |
if today.day == 15 and today.isoweekday() not in (6, 7): | |
print("It's payday today!") | |
sys.exit(0) | |
return (next_payday(today) - today).days | |
if __name__ == "__main__": | |
days = days_until_payday() | |
money_per_day = get_money() / days | |
print("It's {0} days until payday".format(days)) | |
print("You can spend {0} crowns per day".format(money_per_day)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment