-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
38 lines (28 loc) · 776 Bytes
/
data.py
File metadata and controls
38 lines (28 loc) · 776 Bytes
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
import datetime
import json
import time
def get_readings():
with open("readings.json") as f:
return f.read()
class Data:
def __init__(self):
self.status = "on"
self.altitude = 0
self.rotation_x = 0
self.rotation_y = 0
self.rotation_z = 0
def get_json(self):
return json.dumps(self, default=lambda o: o.__dict__)
def get_list(self):
return json.loads(self.get_json())
def update(self):
self.write_to("readings.json")
return self.get_json()
def write_to(self, filename):
with open(filename, "w+") as f:
f.write(self.get_json())
f.write(chr(3))
f.close()
if __name__ == "__main__":
d = Data()
print(d.get_json())