battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

the LivinGrimoire Artificial General Intelligence software design pattern forum

descriptionPython DiCPUTamaguchi get laptop battery info livingrimoire tamaguchi style skill EmptyPython DiCPUTamaguchi get laptop battery info livingrimoire tamaguchi style skill

more_horiz
to add skill in main:
chobit.addSkill(DiCPUTamaguchi())

Code:

class DiCPUTamaguchi(DiSkillV2):
    def __init__(self):
        super().__init__()

    def input(self, ear, skin, eye):
        match ear:
            case "battery":
                self.setSimpleAlg(self.get_battery_percentage())
            case "are you eating":
                self.setSimpleAlg(self.isPlugged())
            case "are you hungry":
                hunger: int = self.get_battery_percentageInt()
                if hunger == 100:
                    self.setSimpleAlg(f"no I am full")
                else:
                    self.setSimpleAlg(f"I am missing{100 - hunger}%")

    @staticmethod
    def get_battery_percentage():
        battery = psutil.sensors_battery()
        if battery is None:
            return "No battery found."
        return f"Battery Percentage: {battery.percent}%"

    @staticmethod
    def isPlugged():
        battery = psutil.sensors_battery()
        if battery is None:
            return "No battery found."
        return f"**Power plugged in**: {battery.power_plugged}"

    @staticmethod
    def is_battery_plugged() -> bool:
        battery_info = psutil.sensors_battery()
        if battery_info is None:
            return False  # No battery found
        return battery_info.power_plugged

    @staticmethod
    def get_battery_percentageInt() -> int:
        battery = psutil.sensors_battery()
        if battery is None:
            return -1
        return battery.percent

descriptionPython DiCPUTamaguchi get laptop battery info livingrimoire tamaguchi style skill EmptyRe: Python DiCPUTamaguchi get laptop battery info livingrimoire tamaguchi style skill

more_horiz
https://rumble.com/v4gozf3-livingrimoire-cpu-info-skill-python.html

updated the skill with more features.

Code:

class DiCPUTamaguchi(DiSkillV2):
    def __init__(self):
        super().__init__()

    def input(self, ear, skin, eye):
        # cpu info getters
        match ear:
            case "battery":
                self.setSimpleAlg(self.get_battery_percentage())
            case "are you eating":
                self.setSimpleAlg(self.isPlugged())
            case "are you hungry":
                hunger: int = self.get_battery_percentageInt()
                if hunger == 100:
                    self.setSimpleAlg(f"no I am full")
                else:
                    self.setSimpleAlg(f"I am missing{100 - hunger}%")
            case "cpu usage":
                self.setSimpleAlg(self.get_cpu_usage())

    @staticmethod
    def get_battery_percentage():
        battery = psutil.sensors_battery()
        if battery is None:
            return "No battery found."
        return f"Battery Percentage: {battery.percent}%"

    @staticmethod
    def isPlugged():
        battery = psutil.sensors_battery()
        if battery is None:
            return "No battery found."
        return f"**Power plugged in**: {battery.power_plugged}"

    @staticmethod
    def is_battery_plugged() -> bool:
        battery_info = psutil.sensors_battery()
        if battery_info is None:
            return False  # No battery found
        return battery_info.power_plugged

    @staticmethod
    def get_battery_percentageInt() -> int:
        battery = psutil.sensors_battery()
        if battery is None:
            return -1
        return battery.percent

    @staticmethod
    def get_cpu_usage():
        """
        Returns the current system-wide CPU usage percentage.
        """
        return f"{psutil.cpu_percent()}"
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply