-
Notifications
You must be signed in to change notification settings - Fork 1
/
powerc.py
53 lines (37 loc) · 1.08 KB
/
powerc.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'''Coded By SagaR'''
from flask import Flask
import flask
import json
from datetime import datetime
from flask_cors import CORS, cross_origin
import os
def power():
x=os.popen("echo - | awk \"{printf \
$(( \
$(cat /sys/class/power_supply/BAT1/current_now) * \
$(cat /sys/class/power_supply/BAT1/voltage_now) \
)) / 1000000000000 }\"").read()
#print(x)
x=str(x)
now=datetime.now()
time = now.strftime("%Y/%m/%d %H:%M:%S")
d=[]
d.insert(0,{"time":time})
d.insert(1,{"power":str(x)})
return d
from flask import Flask, send_file, make_response
app = Flask(__name__)
#app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
CORS(app)
#api = Api(app)
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
return response
@app.route('/', methods=['GET'])
def data_matrix():
return flask.jsonify(power())
if __name__ == '__main__':
app.run(host = '0.0.0.0',port=5000)