Last active
August 20, 2018 05:49
-
-
Save uetchy/419dfd2b75af162cd51db1f9d0a189f5 to your computer and use it in GitHub Desktop.
Revisions
-
uetchy revised this gist
Aug 20, 2018 . 1 changed file with 7 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ #!/usr/bin/env python from __future__ import print_function import subprocess import re @@ -21,12 +24,11 @@ def parseIOReg(rawResult): print('Max Capacity:', maxCapacity, 'mAh') print('Design Capacity:', designCapacity, 'mAh') print('Cycle Count:', cycleCount, 'cycles') print('Cycle Count Remaining: {} cycles - {}% reached'.format( 1000 - cycleCount, round(float(cycleCount) / 1000 * 100))) availability = float(maxCapacity) / designCapacity print('Battery Availability: {}%'.format(round(availability * 100, 1))) if (availability < 0.8): print( -
uetchy created this gist
Aug 7, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import subprocess import re def getIOReg(): cmd = "ioreg -l | grep Capacity" response = subprocess.check_output(cmd, shell=True) return response.decode('utf-8') def parseIOReg(rawResult): maxCapacity = int(re.search(r'"MaxCapacity" = (\d+)\n', rawResult).group(1)) designCapacity = int( re.search(r'"DesignCapacity" = (\d+)\n', rawResult).group(1)) cycleCount = int(re.search(r'"Cycle Count"=(\d+)\}', rawResult).group(1)) return [maxCapacity, designCapacity, cycleCount] if __name__ == '__main__': maxCapacity, designCapacity, cycleCount = parseIOReg(getIOReg()) print('Max Capacity:', maxCapacity, 'mAh') print('Design Capacity:', designCapacity, 'mAh') print('Cycle Count:', cycleCount, 'cycles') print( f'Cycle Count Remaining: {1000 - cycleCount} cycles - {round(cycleCount / 1000 * 100)}% reached' ) availability = maxCapacity / designCapacity print(f'Battery Availability: {round(availability * 100, 1)}%') if (availability < 0.8): print( '===> Your battery is eligible for free battery replacement service in AppleCare+. Repair it now!' )