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 json
import os import os
import time import time
import urllib.request, json
import datetime import datetime
import tweepy import tweepy
from mastodon import Mastodon 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 = 1
state_b4 = 1 state_b4 = 1
@ -101,15 +100,18 @@ while True:
time_now = time.time() time_now = time.time()
if state != state_b4:
file_status_path = dir_path + os.sep + "status.json" 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: if state == 1 and state_b4 == 0:
time_opening = datetime.datetime.fromtimestamp(int(time_now)).strftime('%Y-%m-%d %H:%M:%S') time_opening = datetime.datetime.fromtimestamp(int(time_now)).strftime('%Y-%m-%d %H:%M:%S')
print("open", time_opening) 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 = len(data_status["opening_text"])
number = textselect(0, number - 1) 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') time_closing = datetime.datetime.fromtimestamp(int(time_now)).strftime('%Y-%m-%d %H:%M:%S')
print("closed", time_closing) 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 = len(data_status["closing_text"])
number = textselect(0, number - 1) number = textselect(0, number - 1)