Continue Flask migration.
This commit is contained in:
parent
a191565a44
commit
5c85e194a3
@ -13,6 +13,7 @@ import time
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
# This code has been written for
|
# This code has been written for
|
||||||
|
# python3 3.11.2-1+b1
|
||||||
# python3-flask 2.2.2-3 all micro web framework based on Werkzeug and Jinja2 - Python 3.x
|
# python3-flask 2.2.2-3 all micro web framework based on Werkzeug and Jinja2 - Python 3.x
|
||||||
# python3-flask-migrate 4.0.4-1 all SQLAlchemy migrations for Flask using Alembic and Python 3
|
# python3-flask-migrate 4.0.4-1 all SQLAlchemy migrations for Flask using Alembic and Python 3
|
||||||
# python3-flask-sqlalchemy 3.0.3-1 all adds SQLAlchemy support to your Python 3 Flask application
|
# python3-flask-sqlalchemy 3.0.3-1 all adds SQLAlchemy support to your Python 3 Flask application
|
||||||
@ -120,7 +121,7 @@ def get_metric(metric, current_time, interval):
|
|||||||
try:
|
try:
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
data = json.loads(r.text)
|
data = json.loads(r.text)
|
||||||
timestamp = getDateTimeFromISO8601String(data['timestamp']).replace(tzinfo=timezone.utc).timestamp()
|
timestamp = datetime.fromisoformat(data['timestamp']).replace(tzinfo=timezone.utc).timestamp()
|
||||||
if current_time - timestamp < interval * 2:
|
if current_time - timestamp < interval * 2:
|
||||||
return data['value']
|
return data['value']
|
||||||
else:
|
else:
|
||||||
@ -138,7 +139,7 @@ def get_forced_mode():
|
|||||||
#cur.execute("SELECT value, timestamp FROM set_mode WHERE name='mode'")
|
#cur.execute("SELECT value, timestamp FROM set_mode WHERE name='mode'")
|
||||||
#row = cur.fetchone()
|
#row = cur.fetchone()
|
||||||
data = dict(zip(['value', 'timestamp'], row))
|
data = dict(zip(['value', 'timestamp'], row))
|
||||||
timestamp = getDateTimeFromISO8601String(data['timestamp']).replace(tzinfo=timezone.utc).timestamp()
|
timestamp = datetime.fromisoformat(data['timestamp']).replace(tzinfo=timezone.utc).timestamp()
|
||||||
# We ignore old targets but never ignore absence modes
|
# We ignore old targets but never ignore absence modes
|
||||||
if data['value'] in targets and time.time() - timestamp > forced_mode_duration:
|
if data['value'] in targets and time.time() - timestamp > forced_mode_duration:
|
||||||
logging.debug("Ignoring old set mode.")
|
logging.debug("Ignoring old set mode.")
|
||||||
@ -330,14 +331,7 @@ logging.info("====== Ended successfully ======")
|
|||||||
#from http.server import BaseHTTPRequestHandler
|
#from http.server import BaseHTTPRequestHandler
|
||||||
#import threading
|
#import threading
|
||||||
#import socketserver
|
#import socketserver
|
||||||
#
|
|
||||||
## As of Python 3.7 there is a method datetime.fromisoformat() which is exactly the reverse for isoformat().
|
|
||||||
## So this will no longer be necessary.
|
|
||||||
#from dateutil import parser
|
|
||||||
#def getDateTimeFromISO8601String(s):
|
|
||||||
# d = parser.parse(s)
|
|
||||||
# return d
|
|
||||||
#
|
|
||||||
#from threading import Lock
|
#from threading import Lock
|
||||||
#
|
#
|
||||||
#xprint_lock = Lock()
|
#xprint_lock = Lock()
|
||||||
|
Loading…
Reference in New Issue
Block a user