Browse Source

Fixed Ventil feature, Added Alarm feature

Signed-off-by: chanhoonseng <chanhoonseng3101@gmail.com>
chanhoonseng 7 years ago
parent
commit
a98eac091b
2 changed files with 30 additions and 7 deletions
  1. 29 6
      core.py
  2. 1 1
      designer.html

+ 29 - 6
core.py

@@ -11,6 +11,7 @@ import datetime
 from shutil import copyfile
 from time import gmtime, strftime
 import time
+import smtplib
 
 
 import tornado.escape
@@ -84,10 +85,10 @@ def fetchDataADEI():
     curtime = int(time.time())
     time_range = str((curtime-3600)) + "-" + str(curtime)
     for param in varname:
-        print param
+        #print param
         dest = config['server'] + config['script']
         url = dest + "?" + varname[param] + "&window=" + time_range
-        print url
+        #print url
         data = requests.get(url,
                             auth=(config['username'],
                                   config['password'])).content
@@ -97,15 +98,37 @@ def fetchDataADEI():
 
         last_value = data.split(",")[-1].strip()
 	try:
-            print last_value
+            #print last_value
             test_x = float(last_value)
         except ValueError:
             last_value = ""
- 	print last_value
+ 	#print last_value
         cache_data[param] = last_value
         #current_timestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())
         current_timestamp = strftime("%Y-%m-%d %H:%M:%S")
         cache_data['time'] = current_timestamp
+        time_pattern = "%Y-%m-%d %H:%M:%S"
+        epoch_cur = int(time.mktime(time.strptime(current_timestamp, time_pattern)))
+        #print("current: ", epoch_cur)
+    
+
+    with open("cache.yaml",'r') as stream_cache:
+        cache_content = {}
+        cache_content = yaml.load(stream_cache)
+        #print(cache_content)
+        time_prev = cache_content.get('time')
+        #time_pattern = "%Y-%m-%d %H:%M:%S"
+        epoch_prev = int(time.mktime(time.strptime(time_prev, time_pattern)))
+        print("previous:", epoch_prev)
+
+    if epoch_cur == epoch_prev:
+        server = smtplib.SMTP('smtp.gmail.com', 587)
+        server.starttls()
+        server.login("server.bora@gmail.com", "not2peepinsider")
+        msg = "Katrin is running!"
+        server.sendmail("server.bora@gmail.com", "chanhoonseng3101@gmail.com", msg)
+        server.quit()
+
 
     with open(".tmp.yaml", 'w') as stream_tmp:
         stream_tmp.write(yaml.dump(cache_data, default_flow_style=False))
@@ -369,10 +392,10 @@ class GetDataHandler(tornado.web.RequestHandler):
                 cache_data = yaml.load(stream)
             except yaml.YAMLError as exc:
                 print(exc)
-        print("GetData:")
+        #print("GetData:")
         if cache_data == None:
             cache_data = {}
-        print cache_data
+        #print cache_data
         self.write(cache_data) 
 
     

+ 1 - 1
designer.html

@@ -85,7 +85,7 @@
 {% end %}
 
 
-{% if data['style'][key]['type'] == "valve" %}
+{% if data['style'][key]['type'] == "ventil" %}
 <div style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px;' data-type="{{ data['style'][key]['type'] }}" data-off="{{ data['style'][key]['off'] }}" data-on="{{ data['style'][key]['on'] }}" class='varbox' id="{{ key }}">
 <img width='100%' height='100%' src='{{ static_url("ventil_inactive.png") }}'></img>
 </div>