-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
51 lines (35 loc) · 1.08 KB
/
data.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
import datetime
now = datetime.datetime.now()
def log(temp, ph, salinity):
data = f"{now.date()}x{now.time()}x{temp}x{ph}x{salinity}"
try:
with open("log.txt", 'a') as logFile:
logFile.write(data + "\n")
except IOError:
with open("log.txt", "w") as logFile:
logFile.write("LOG\n")
logFile.write(data + "\n")
def fetch():
with open("log.txt", "r") as logFile:
readlines = logFile.read().splitlines()
log1 = readlines[-1].split('x')
log2 = readlines[-2].split('x')
log3 = readlines[-3].split('x')
log4 = readlines[-4].split('x')
log5 = readlines[-5].split('x')
log = [log1, log2, log3, log4, log5]
return log
def fetchAll():
logFull = []
with open("log.txt", "r") as logFile:
readlines = logFile.read().splitlines()
for line in readlines:
parts = line.split('x')
logFull.append(parts)
return logFull
def get():
temp = 28
ph = 7.1
salinity = 1234
data = [temp, ph, salinity]
return data