テスト用のあれこれ共用フォルダ
Revision | 431e63a05e93bee485a44c75709c0e9bc8a5dd36 (tree) |
---|---|
Time | 2018-03-09 17:43:36 |
Author | takemasa <suikan@user...> |
Commiter | takemasa |
Power mesurement script is OK
@@ -4,35 +4,51 @@ Created on 2018/03/09 | ||
4 | 4 | @author: takemasa |
5 | 5 | ''' |
6 | 6 | from _datetime import datetime |
7 | +import time | |
8 | +import os | |
7 | 9 | |
8 | -if __name__ == '__main__': | |
9 | - #テキストファイルの読み込み | |
10 | - with open("/sys/class/power_supply/BAT0/energy_now", "r") as f: # 電池内部のエネルギー残量[W] | |
11 | - data = f.read() # ひとまとまりのデータとして読み込む | |
12 | - | |
13 | - data = data.split("\n") # 改行コードで1行ずつに分割 | |
14 | - energy_now = int(data[0])/1000000 | |
15 | 10 | |
16 | - with open("/sys/class/power_supply/BAT0/energy_full", "r") as f: # 充電可能なエネルギー[w] | |
17 | - data = f.read() # ひとまとまりのデータとして読み込む | |
18 | - | |
19 | - data = data.split("\n") # 改行コードで1行ずつに分割 | |
20 | - energy_full = int(data[0])/1000000 | |
11 | +if __name__ == '__main__': | |
12 | + home = os.environ['HOME'] | |
21 | 13 | |
22 | - with open("/sys/class/power_supply/BAT0/voltage_now", "r") as f: # 電圧 | |
14 | + with open("/sys/class/power_supply/BAT0/model_name", "r") as f: #バッテリモデル名 | |
23 | 15 | data = f.read() # ひとまとまりのデータとして読み込む |
24 | - | |
25 | - data = data.split("\n") # 改行コードで1行ずつに分割 | |
26 | - voltage_now = int(data[0])/1000000 | |
16 | + data = data.split("\n") # 改行コードで1行ずつに分割 | |
17 | + model_name = data[0] | |
18 | + f.close() | |
27 | 19 | |
28 | - with open("/sys/class/power_supply/BAT0/model_name", "r") as f: #モデル名 | |
29 | - data = f.read() # ひとまとまりのデータとして読み込む | |
30 | - | |
31 | - data = data.split("\n") # 改行コードで1行ずつに分割 | |
32 | - model_name = data[0] | |
20 | + #テキストファイルの読み込み | |
21 | + | |
22 | + while(True): | |
23 | + with open("/sys/class/power_supply/BAT0/energy_now", "r") as f: # 電池内部のエネルギー残量[W] | |
24 | + data = f.read() # ひとまとまりのデータとして読み込む | |
25 | + data = data.split("\n") # 改行コードで1行ずつに分割 | |
26 | + energy_now = int(data[0])/1000000 | |
27 | + f.close() | |
33 | 28 | |
34 | -# d = datetime.now().strftime("%Y/%b/%d %X") | |
35 | - d = datetime.now().isoformat() | |
29 | + with open("/sys/class/power_supply/BAT0/energy_full", "r") as f: # 充電可能なエネルギー[w] | |
30 | + data = f.read() # ひとまとまりのデータとして読み込む | |
31 | + data = data.split("\n") # 改行コードで1行ずつに分割 | |
32 | + energy_full = int(data[0])/1000000 | |
33 | + f.close() | |
34 | + | |
35 | + with open("/sys/class/power_supply/BAT0/voltage_now", "r") as f: # 電圧 | |
36 | + data = f.read() # ひとまとまりのデータとして読み込む | |
37 | + data = data.split("\n") # 改行コードで1行ずつに分割 | |
38 | + voltage_now = int(data[0])/1000000 | |
39 | + f.close() | |
36 | 40 | |
37 | - # model, time, full, energy now, voltage | |
38 | - print([model_name, d, energy_full, energy_now, voltage_now]) | |
\ No newline at end of file | ||
41 | + | |
42 | + # d = datetime.now().strftime("%Y/%b/%d %X") | |
43 | + d = datetime.now().isoformat() | |
44 | + | |
45 | + rec = str([d, energy_full, energy_now, voltage_now]) | |
46 | + | |
47 | + with open(home+"/Documents/battery/"+model_name, mode="a", encoding="utf-8") as f: #バッテリモデル名 | |
48 | + f.write(rec) | |
49 | + f.close() | |
50 | + | |
51 | + print(rec) | |
52 | + | |
53 | + time.sleep(30) | |
54 | + | |
\ No newline at end of file |