added error hanelign for first run

This commit is contained in:
Askill 2024-03-03 11:57:10 +01:00
parent 90e2cff0c5
commit 6390a1bef4
1 changed files with 17 additions and 14 deletions

View File

@ -14,25 +14,28 @@ def get_ordered_files(dir_name):
def get_next_tn(dir_name): def get_next_tn(dir_name):
current_path = dir_name +"/current.json" current_path = dir_name +"/current.json"
with open(current_path, 'r') as openfile:
current_tn = json.load(openfile)
tns = get_ordered_files(dir_name) tns = get_ordered_files(dir_name)
tn_name = "" if os.path.isfile(current_path):
for i, tn in enumerate(tns): with open(current_path, 'r') as openfile:
if tn == current_tn["current"]: current_tn = json.load(openfile)
tn_name = tns[(i+1)%len(tns)]
break
if tn_name == current_tn["current"]: tn_name = ""
# nothing changed for i, tn in enumerate(tns):
return None if tn == current_tn["current"]:
elif tn_name == "": tn_name = tns[(i+1)%len(tns)]
# old thumbnail was not found in dir break
if tn_name == current_tn["current"]:
# nothing changed
return None
elif tn_name == "":
# old thumbnail was not found in dir
tn_name = tns[0]
else:
tn_name = tns[0] tn_name = tns[0]
current_tn["current"] = tn_name current_tn = {"current":tn_name}
with open(current_path, "r") as outfile: with open(current_path, "r") as outfile:
outfile.write(json.dumps(current_tn)) outfile.write(json.dumps(current_tn))