diff --git a/PointsInflation.py b/PointsInflation.py new file mode 100644 index 0000000..754583c --- /dev/null +++ b/PointsInflation.py @@ -0,0 +1,55 @@ +import sys +import os +import numpy as np +from datetime import datetime + +# Creates inflation in the points adminstration. +# This script is not directly triggered by the bot, but may be executed once per day. + + +# When developing on an inferior Windows machine, you'll need this: +if sys.platform == "win32": + os.EX_OK = 0 + os.EX_IOERR = 5 + os.EX_USAGE = 99 + + +POINTS_FILE = "pointscount.npy" +BANK_ID = 42 + + +# Read current points balance: +try: + pointsCount = np.load(POINTS_FILE).item() +except: + sys.stderr.write("Cannot open points file: " + POINTS_FILE) + sys.exit(os.EX_IOERR) +if BANK_ID not in pointsCount.keys(): + sys.stderr.write("Cannot find the bank's balance.") + sys.exit(os.EX_IOERR) + + +# Make sure inflation is only executed once per day: +currentDateStr = datetime.now().strftime("%Y%m%d") + +if "lastInflationUpdate" in pointsCount[BANK_ID]: + if pointsCount[BANK_ID]["lastInflationUpdate"] == currentDateStr: + sys.stderr.write("We already had some inflation today. No hyperinflation allowed!") + sys.exit(os.EX_USAGE) + + +# increase the bank's points by 1: +pointsCount[BANK_ID]["points"] += 1 +pointsCount[BANK_ID]["lastInflationUpdate"] = currentDateStr + + +# save file: +try: + np.save(POINTS_FILE, pointsCount) +except: + sys.stderr.write("Cannot save to points file: " + POINTS_FILE) + sys.exit(os.EX_IOERR) + + +sys.stdout.write("Inflation complete. Hooray for capitalism!") +sys.exit(os.EX_OK) \ No newline at end of file