|
@@ -1,3 +1,4 @@
|
|
|
+from __future__ import print_function
|
|
|
import logging
|
|
|
import calendar
|
|
|
import datetime
|
|
@@ -123,13 +124,12 @@ def fetchDataADEI():
|
|
|
first_value = "-".join(time_buffer)
|
|
|
first_ts = calendar.timegm(datetime.datetime.strptime(first_value, "%d-%m-%y %H:%M:%S.%f").timetuple())
|
|
|
except:
|
|
|
- first_ts = ""
|
|
|
-
|
|
|
- cache_data[param] = {'timestamp': first_ts, 'value': last_value}
|
|
|
+ first_ts = ""
|
|
|
+ cache_data[param] = {'timestamp': first_ts, 'value': last_value}
|
|
|
|
|
|
current_timestamp = strftime("%Y-%m-%d %H:%M:%S")
|
|
|
cache_data['time'] = current_timestamp
|
|
|
-
|
|
|
+
|
|
|
with open("./bora/.tmp.yaml", 'w') as stream_tmp:
|
|
|
stream_tmp.write(yaml.dump(cache_data, default_flow_style=False))
|
|
|
src_file = os.getcwd() + "/bora/.tmp.yaml"
|
|
@@ -156,25 +156,25 @@ class ListHandler(tornado.web.RequestHandler):
|
|
|
|
|
|
class StartHandler(tornado.web.RequestHandler):
|
|
|
def get(self):
|
|
|
- print "Start fetchData"
|
|
|
+ print("Start fetchData")
|
|
|
rt.start()
|
|
|
|
|
|
|
|
|
class StopHandler(tornado.web.RequestHandler):
|
|
|
def get(self):
|
|
|
- print "Stop fetchData"
|
|
|
+ print("Stop fetchData")
|
|
|
rt.stop()
|
|
|
|
|
|
|
|
|
class SetTimerHandler(tornado.web.RequestHandler):
|
|
|
def get(self, duration):
|
|
|
- print "Set interval"
|
|
|
+ print("Set interval")
|
|
|
rt.setInterval(float(duration))
|
|
|
|
|
|
|
|
|
class DesignerHandler(tornado.web.RequestHandler):
|
|
|
def get(self):
|
|
|
- print "In designer mode."
|
|
|
+ print("In designer mode.")
|
|
|
with open("./bora/cache.yaml", 'r') as stream:
|
|
|
try:
|
|
|
cache_data = yaml.load(stream)
|
|
@@ -192,8 +192,7 @@ class DesignerHandler(tornado.web.RequestHandler):
|
|
|
else:
|
|
|
index_data = cache_data
|
|
|
|
|
|
- if index_data is not None:
|
|
|
- index_data = sorted(index_data)
|
|
|
+ if index_data is not None: index_data = sorted(index_data)
|
|
|
|
|
|
data = {
|
|
|
"cache": cache_data,
|
|
@@ -227,7 +226,7 @@ class SaveHandler(tornado.web.RequestHandler):
|
|
|
|
|
|
def post(self):
|
|
|
json_obj = json_decode(self.request.body)
|
|
|
-
|
|
|
+
|
|
|
with open("style.yaml", 'w') as output:
|
|
|
output.write(yaml.safe_dump(json_obj, encoding='utf-8',
|
|
|
allow_unicode=True, default_flow_style=False))
|
|
@@ -236,7 +235,7 @@ class SaveHandler(tornado.web.RequestHandler):
|
|
|
|
|
|
class StatusHandler(tornado.web.RequestHandler):
|
|
|
def get(self):
|
|
|
- print "In status mode."
|
|
|
+ print("In status mode.")
|
|
|
with open("style.yaml", 'r') as stream:
|
|
|
try:
|
|
|
style_data = yaml.load(stream)
|
|
@@ -249,8 +248,8 @@ class StatusHandler(tornado.web.RequestHandler):
|
|
|
except yaml.YAMLError as exc:
|
|
|
print(exc)
|
|
|
|
|
|
- if not os.path.isfile("./bora/cache.yaml"):
|
|
|
- print "BORA is loading data, please refresh the page again in a moment."
|
|
|
+ if not os.path.isfile("./bora/cache.yaml"):
|
|
|
+ print("BORA is loading data, please refresh the page again in a moment.")
|
|
|
open("./bora/cache.yaml","w")
|
|
|
|
|
|
with open("./bora/cache.yaml", 'r') as vstream:
|
|
@@ -274,7 +273,7 @@ class StatusHandler(tornado.web.RequestHandler):
|
|
|
|
|
|
class UpdateHandler(tornado.web.RequestHandler):
|
|
|
def get(self):
|
|
|
- print "Update Sensor Definition"
|
|
|
+ print("Update Sensor Definition")
|
|
|
new_data = {}
|
|
|
rt.stop()
|
|
|
with open("varname.yaml", 'r') as stream:
|
|
@@ -375,7 +374,7 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
|
|
|
|
|
|
data = requests.get(
|
|
|
url,
|
|
|
- auth=(os.environ["BORA_ADEI_USERNAME"],
|
|
|
+ auth=(os.environ["BORA_ADEI_USERNAME"],
|
|
|
os.environ["BORA_ADEI_PASSWORD"])
|
|
|
)
|
|
|
cr = data.content
|
|
@@ -457,21 +456,21 @@ class AdeiKatrinHandler(tornado.web.RequestHandler):
|
|
|
class GetDataHandler(tornado.web.RequestHandler):
|
|
|
def get(self):
|
|
|
cache_data = None
|
|
|
- if not os.path.isfile("./bora/cache.yaml"):
|
|
|
- print "BORA is loading data, please refresh the page again in a moment."
|
|
|
+ if not os.path.isfile("./bora/cache.yaml"):
|
|
|
+ print("BORA is loading data, please refresh the page again in a moment.")
|
|
|
open("./bora/cache.yaml","w")
|
|
|
with open("./bora/cache.yaml", 'r') as stream:
|
|
|
try:
|
|
|
cache_data = yaml.load(stream)
|
|
|
except yaml.YAMLError as exc:
|
|
|
-
|
|
|
+
|
|
|
print(exc)
|
|
|
if cache_data is None:
|
|
|
cache_data = {}
|
|
|
self.write(cache_data)
|
|
|
|
|
|
|
|
|
-print "Running..."
|
|
|
+print("Running...")
|
|
|
rt = RepeatedTimer(int(os.environ["BORA_POLLING"]), fetchDataADEI)
|
|
|
|
|
|
application = tornado.web.Application([
|