diff --git a/libs/resources/resources/__init__.py b/libs/resources/resources/__init__.py index cdc5d38..36c4497 100644 --- a/libs/resources/resources/__init__.py +++ b/libs/resources/resources/__init__.py @@ -1,3 +1,5 @@ from .fossil import Oil, Coal, NaturalGas from .synthetic import Nuclear from .renewable import Wind, Solar, Water +from .powergrid import PowerGrid +from .namelog import UserLog \ No newline at end of file diff --git a/libs/resources/resources/log.json b/libs/resources/resources/log.json new file mode 100644 index 0000000..1ffc5f0 --- /dev/null +++ b/libs/resources/resources/log.json @@ -0,0 +1 @@ +[{"user": "Shnacko", "time": 1682952779.590532, "wind": 4533.017306686408, "solar": 0, "coal": 0, "oil": 0, "nuclear": 0, "natural_gas": 0}] \ No newline at end of file diff --git a/libs/resources/resources/namelog.py b/libs/resources/resources/namelog.py new file mode 100644 index 0000000..d283146 --- /dev/null +++ b/libs/resources/resources/namelog.py @@ -0,0 +1,31 @@ +import json +import os +import getpass +from datetime import datetime +import time + +class UserLog: + + def log_user(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gas = 0): + path = os.path.dirname(__file__) + with open(f"{path}/log.json", "r") as fh: + log = json.load(fh) + + name = getpass.getuser() + now = datetime.now().timestamp() + + entry = { + "user": name, + "time": now, + "wind": wind, + "solar": solar, + "coal": coal, + "oil": oil, + "nuclear": nuclear, + "natural_gas": natural_gas + } + + log.append(entry) + + with open(f"{path}/log.json", "w") as fh: + json.dump(log, fh) \ No newline at end of file diff --git a/libs/resources/resources/powergrid.py b/libs/resources/resources/powergrid.py new file mode 100644 index 0000000..457c9ea --- /dev/null +++ b/libs/resources/resources/powergrid.py @@ -0,0 +1,38 @@ +import json +import sys +import os + +class PowerGrid: + + #Turn this perameter into a dictionary + def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass = 0): + # sorts power based on its source and adds it to the power grid + path = os.path.dirname(__file__) + renewable_energy = wind + solar + exhaustable_energy = coal + oil + nuclear + natural_gass + with open(f"{path}/worldbattery.json", "r") as fh: + world_battery = json.load(fh) + world_battery["renewable_energy"] += renewable_energy + world_battery["exhaustable_energy"] += exhaustable_energy + with open(f"{path}/worldbattery.json", "w") as add_battery: + json.dump(world_battery, add_battery) + + # Takes a perameter that is the ammount of power it takes to run the object + def use_power(power): + path = os.path.dirname(__file__) + with open(f"{path}/worldbattery.json", "r") as fh: + world_battery = json.load(fh) + + if world_battery["renewable_energy"] >= power: + world_battery["renewable_energy"] -= power + print("You Can Feel Good Knowing This Was Powered By Renewable Energy! ") + elif world_battery["exhaustable_energy"] >= power: + world_battery["exhaustable_energy"] -= power + print("Hope you are happy. You powered it, but now the earth is a little more polluted.") + print("🏭") + elif world_battery["renewable_energy"] < power and world_battery["exhaustable_energy"] < power: + print("There Is Not Enough Power In The World. Generate Some More And Try Again. ") + sys.exit() + + with open(f"{path}/worldbattery.json", "w") as add_battery: + json.dump(world_battery, add_battery) \ No newline at end of file diff --git a/libs/resources/resources/worldbattery.json b/libs/resources/resources/worldbattery.json new file mode 100644 index 0000000..d4bee0a --- /dev/null +++ b/libs/resources/resources/worldbattery.json @@ -0,0 +1 @@ +{"renewable_energy": 54332.16092373188, "exhaustable_energy": 52808} \ No newline at end of file