|
|
|
@ -15,7 +15,7 @@ path = Path(__file__).resolve().parent
|
|
|
|
|
def update_db(payload): |
|
|
|
|
conn = None |
|
|
|
|
try: |
|
|
|
|
db = (str(path) + "/db.sqlite3") |
|
|
|
|
db = (str(path) + "/data/db.sqlite3") |
|
|
|
|
conn = sqlite3.connect(db) |
|
|
|
|
|
|
|
|
|
c = conn.cursor() |
|
|
|
@ -76,12 +76,12 @@ def secs_to_HMS(secs):
|
|
|
|
|
|
|
|
|
|
def record_file_exist(): |
|
|
|
|
""" Check if records file exist """ |
|
|
|
|
return os.path.isfile('data.csv') |
|
|
|
|
return os.path.isfile('data/data.csv') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_record_file(): |
|
|
|
|
""" Create a new record file """ |
|
|
|
|
with open('data.csv', 'a') as csvfile: |
|
|
|
|
with open('data/data.csv', 'a') as csvfile: |
|
|
|
|
columns = ['timestamp', 'status'] |
|
|
|
|
writer = csv.DictWriter(csvfile, fieldnames=columns) |
|
|
|
|
writer.writeheader() |
|
|
|
@ -90,7 +90,7 @@ def create_record_file():
|
|
|
|
|
def last_record_status(): |
|
|
|
|
""" Get last record """ |
|
|
|
|
result = None |
|
|
|
|
with open('data.csv', 'r') as csvfile: |
|
|
|
|
with open('data/data.csv', 'r') as csvfile: |
|
|
|
|
reader = csv.DictReader(csvfile) |
|
|
|
|
for row in reader: |
|
|
|
|
result = row |
|
|
|
@ -99,7 +99,7 @@ def last_record_status():
|
|
|
|
|
|
|
|
|
|
def write_record(status): |
|
|
|
|
""" Create a new record """ |
|
|
|
|
with open('data.csv', 'a') as csvfile: |
|
|
|
|
with open('data/data.csv', 'a') as csvfile: |
|
|
|
|
columns = ['timestamp', 'status'] |
|
|
|
|
writer = csv.DictWriter(csvfile, fieldnames=columns) |
|
|
|
|
writer.writerow({'timestamp': str(current_timestamp()), 'status': status}) |
|
|
|
@ -110,7 +110,7 @@ def get_total_downtime():
|
|
|
|
|
seconds = 0 |
|
|
|
|
down = None |
|
|
|
|
up = None |
|
|
|
|
with open('data.csv', 'r') as csvfile: |
|
|
|
|
with open('data/data.csv', 'r') as csvfile: |
|
|
|
|
reader = csv.DictReader(csvfile) |
|
|
|
|
for record in reader: |
|
|
|
|
try: |
|
|
|
|