diff --git a/Battery_notification/Battery_notification.py b/Battery_notification/Battery_notification.py new file mode 100644 index 0000000..a2c7338 --- /dev/null +++ b/Battery_notification/Battery_notification.py @@ -0,0 +1,42 @@ +import psutil +import time +import pyttsx3 +from win10toast import ToastNotifier # also need to install win32api +import threading + +toaster = ToastNotifier() +x=pyttsx3.init() +x.setProperty('rate',110) +x.setProperty('volume',3) +count = 0 + +def show_notification(show_text): + toaster.show_toast(show_text, + icon_path='battery_indicator.ico', + duration=10) + # loop the toaster over some period of time + while toaster.notification_active(): + time.sleep(0.005) + +def monitor(): + while (True): + time.sleep(1) + battery = psutil.sensors_battery() + plugged = battery.power_plugged + percent = int(battery.percent) + + if percent < 35: + if plugged == False: + processThread = threading.Thread(target=show_notification, args=("Your Battery at "+str(percent)+"% Please plug the cable",)) # <- note extra ',' + processThread.start() + x.say("Your battery is getting low so charge it right now") + x.runAndWait() + + elif percent >= 98: + if plugged == True: + processThread = threading.Thread(target=show_notification, args=("Charging is getting complete",)) # <- note extra ',' + processThread.start() + x.say("Charging is getting complete") + x.runAndWait() +if __name__ == "__main__": + monitor() diff --git a/Battery_notification/README.md b/Battery_notification/README.md new file mode 100644 index 0000000..8d37492 --- /dev/null +++ b/Battery_notification/README.md @@ -0,0 +1,11 @@ +Here is this python3 code to get a notification/battery alert when the battery is low (35%)and while charging it is 98% it will give notification till you didn't plug-in when it is low(35%) and out when it is 98% for a Windows laptop.Install some Python library by writing some pip code in terminal. + +``` +pip install psutil + +pip install pyttsx3 + +pip install win10toast +``` +than run the file. +using ```python``` for windows and ```python3``` for linux and follow up ```Battery_notification.py``` diff --git a/README.md b/README.md index f0d476a..b407a5b 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ So far, the following projects have been integrated to this repo: |[Image Compressor](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Image_Compressor)|[Prathima Kadari](https://github.com/prathimacode-hub)| |[Test Your Internet Speed](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/TestMyInternetSpeed)|[TheSmartDeveloperr](https://github.com/thesmartdeveloperr)| |[Plagiarism_detector](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Plagiarism_detector)|[Akshita Singhal](https://github.com/akshitasinghal4444)| +|[Battery_notification](https://github.com/hastagABAwesome-Python-Scripts/Battery_notification/)|[Krishna Sharma](https://github.com/krishnasharma1386) ## How to use :