Advertisement
sohotcall

gsBatteryLog.py -- Battery Percentage Logger -- part 2/2

Mar 5th, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import os, re, datetime, time
  2. import winsound
  3. winsound.Beep( 1024, 1000 )
  4. time.sleep( 1 )
  5. winsound.Beep( 2048, 1000 )
  6. print( 'Ready' )
  7. while True:
  8.     file = open( "D:/scripts/.gsBatteryLog.txt", "a" ); # Log file location
  9.     output = os.popen( "wmic Path Win32_Battery Get EstimatedChargeRemaining /Value" ).read()
  10.     percent = re.compile( r"[^0-9]", re.MULTILINE ).sub( "", output )
  11.     msg = datetime.datetime.now().isoformat()[0:19] + " " + percent
  12.     file.write( msg )
  13.     file.write( "\n" )
  14.     file.close()
  15.     print( msg )
  16.     if int( percent ) < 25:
  17.         winsound.Beep( 1024, 1000 )
  18.     elif int( percent ) > 90:
  19.         winsound.Beep( 2048, 1000 )
  20.     time.sleep( 300 )
  21. # Add shortcut `python.exe path\to\gsBatteryLog.py` to Start-up
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement