adds simplification of loading in status.json

This commit is contained in:
bernd2k 2020-01-06 20:10:42 +01:00
parent 5aaf15ef48
commit a143f9feb5

View file

@ -1,7 +1,6 @@
import json
import os
import time
import urllib.request, json
import datetime
import tweepy
from mastodon import Mastodon
@ -74,7 +73,7 @@ MASTODON_API_BASE_URL = data_config["mastodon_api"]["api_base_url"]
# storing the current and the previous states of the door
state = 1
state_b4 = 1
@ -100,16 +99,19 @@ while True:
time_now = time.time()
file_status_path = dir_path + os.sep + "status.json"
if state != state_b4:
file_status_path = dir_path + os.sep + "status.json"
if os.path.exists(file_status_path) == True:
with open(file_status_path, 'r') as f:
data_status = json.load(f)
if state == 1 and state_b4 == 0:
time_opening = datetime.datetime.fromtimestamp(int(time_now)).strftime('%Y-%m-%d %H:%M:%S')
print("open", time_opening)
if os.path.exists(file_status_path) == True:
with open(file_status_path, 'r') as f:
data_status = json.load(f)
number = len(data_status["opening_text"])
number = textselect(0, number - 1)
@ -152,10 +154,6 @@ while True:
time_closing = datetime.datetime.fromtimestamp(int(time_now)).strftime('%Y-%m-%d %H:%M:%S')
print("closed", time_closing)
if os.path.exists(file_status_path) == True:
with open(file_status_path, 'r') as f:
data_status = json.load(f)
number = len(data_status["closing_text"])
number = textselect(0, number - 1)