Coding projects
· Battery.py-- This will run in every 3 hrs and play music
o
when battery level is below 50% when Power
plugged in : False
o when battery level is 90% when Power plugged in : True
# This will run in every 3 hrs and play music when battery level is below 50%
# python script showing battery details
import psutil
from playsound import playsound
import time
while (True):
# function returning time in hh:mm:ss
def convertTime(seconds):
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
return "%d:%02d:%02d" % (hours, minutes, seconds)
# returns a tuple
battery = psutil.sensors_battery()
print("Battery percentage : ", battery.percent)
print("Power plugged in : ", battery.power_plugged)
# converting seconds to hh:mm:ss
print("Battery left : ", convertTime(battery.secsleft))
# import required module
# for playing note.mp3 file
if battery.percent < 50:
playsound('C:/My_Personal_Local_Storage/5secondsofsummervalentine.mp3')
print('playing sound using playsound')
time.sleep(10800)
Comments
Post a Comment