-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog-access.py
34 lines (28 loc) · 946 Bytes
/
log-access.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
import datetime
import os
import subprocess
import time
def cycle():
config_path = os.path.abspath(os.path.dirname(__file__)) + "/log"
array = ["cat", "/sys/class/power_supply/BAT0/capacity"]
percentage = (subprocess.check_output(array)).strip()
array = ["cat", "/sys/class/power_supply/BAT0/status"]
datetimex= str(datetime.datetime.now()).split(".")[0]
status = subprocess.check_output(array)
log_file = open(config_path+"/logfile.txt","a")
if "Discharging" in status:
status = "Discharging"
else:
status = "Charging"
log_file.write(status+",\t"+percentage+"%,\t"+datetimex+"\n")
log_file.close()
def main():
config_path = os.path.abspath(os.path.dirname(__file__)) + "/log"
# print(config_path)
if not os.path.exists(config_path): # create log folder
os.makedirs(config_path)
while True:
cycle()
time.sleep(60)
main()