-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathits_pyWebApp
More file actions
95 lines (77 loc) · 3.4 KB
/
its_pyWebApp
File metadata and controls
95 lines (77 loc) · 3.4 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2022 Joseph Turner (aka Tearran) & contributors
import sys, os, sqlite3
from http.server import BaseHTTPRequestHandler, HTTPServer
path=os.listdir(os.path.dirname(__file__))
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
its_list = ''
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes('''
<!DOCTYPE html>
<html lang="en">
<head>
<title>ITS LKARS
</title>
<style type="text/css" media="screen">
body {background-color:#3c3c3c; color:#ffffff; }
a:link { color:white; text-decoration: none; }
a:visited { color:yellow; text-decoration: none; }
a:hover { color:white; text-decoration: none; }
a:active { color:yellow; text-decoration: underline; }
</style>
</head>
<body>
<H1 style='text-align:center;'>ITS LKARS</H1>
<P style='text-align:center;'>Linux Kernel to Access and Record Sensor data. ( LKARS )</P>
<P style='text-align:center;' >Include This/these Script(s). ( its )</P>
<nav style='text-align:center;'>
<a href="/">Home</a>
''', "utf-8"))
## loop scripts avalible in this folder
runits=''
for x in os.listdir(os.path.dirname(__file__)):
if x.endswith(".py"):
sensor = os.popen(os.path.dirname(__file__)+'/'+x+'').read()
if self.path=='/'+x+'':
self.wfile.write(bytes(' | <a href="/'+x+'"> '+x+' </a> ', "utf-8"))
elif self.path=='/' :
self.wfile.write(bytes(' | <a href="/'+x+'"> '+x+' </a> ', "utf-8"))
pass
runits+='</nav>'
if self.path=='/':
i2c_URL=os.path.dirname(__file__)+'/db/sqlite.db'
conn = sqlite3.connect(i2c_URL)
c = conn.cursor()
c.execute("SELECT * FROM its_i2cList")
rows = c.fetchall()
for row in rows:
if row[6] != "URL not found":
self.wfile.write(bytes("<p>"+row[1]+" <a href="+row[6]+" target='_blank' >"+row[3]+":</a></p>", "utf-8"))
else:
self.wfile.write(bytes("<p>"+row[1]+" "+row[3]+"</p>", "utf-8"))
conn.close
self.wfile.write(bytes(""+runits, "utf-8"))
#cpu_temp = os.popen("/sys/class/thermal/thermal_zone0/temp").read()
cpu_temp = os.popen("/opt/vc/bin/vcgencmd measure_temp").read()
self.wfile.write(bytes('''
<footer>
<label for="temp">CPU Temp:</label><meter id="temp" value="'''+cpu_temp[5:-3:]+'''" min="20" max="80">'''+cpu_temp+''' out of 120</meter><br>
<p>Copyright (c) 2022 Joseph Turner (aka Tearran) & contributors</p>
</footer>
</body>
</html>
''', "utf-8"))
if __name__ == "__main__":
appServer = HTTPServer(('', 8000), MyServer)
print("its local server")
try:
print("started at port 8000")
appServer.serve_forever()
except KeyboardInterrupt:
pass
appServer.server_close()
print("Server stopped.")