Continue Flask migration.
This commit is contained in:
parent
8001a553a2
commit
4301842cca
@ -9,6 +9,8 @@ import yaml
|
||||
import os
|
||||
import sys
|
||||
import datetime
|
||||
from datetime import timezone
|
||||
from datetime import datetime
|
||||
import time
|
||||
import requests
|
||||
|
||||
@ -121,7 +123,7 @@ def get_metric(metric, current_time, interval):
|
||||
try:
|
||||
r = requests.get(url)
|
||||
data = json.loads(r.text)
|
||||
timestamp = data['timestamp'].fromisoformat().replace(tzinfo=timezone.utc).timestamp()
|
||||
timestamp = datetime.fromisoformat(data['timestamp']).replace(tzinfo=timezone.utc).timestamp()
|
||||
if current_time - timestamp < interval * 2:
|
||||
return data['value']
|
||||
else:
|
||||
@ -139,7 +141,7 @@ def get_forced_mode():
|
||||
#cur.execute("SELECT value, timestamp FROM set_mode WHERE name='mode'")
|
||||
#row = cur.fetchone()
|
||||
data = dict(zip(['value', 'timestamp'], row))
|
||||
timestamp = data['timestamp'].fromisoformat().replace(tzinfo=timezone.utc).timestamp()
|
||||
timestamp = datetime.fromisoformat(data['timestamp']).replace(tzinfo=timezone.utc).timestamp()
|
||||
# We ignore old targets but never ignore absence modes
|
||||
if data['value'] in targets and time.time() - timestamp > forced_mode_duration:
|
||||
logging.debug("Ignoring old set mode.")
|
||||
@ -324,7 +326,6 @@ while True:
|
||||
logging.info("====== Ended successfully ======")
|
||||
|
||||
#import subprocess
|
||||
#from datetime import timezone
|
||||
#import argparse
|
||||
#import signal
|
||||
#from threading import Event
|
||||
|
Loading…
Reference in New Issue
Block a user