Add tts support to loader

This commit is contained in:
Tim Van Baak 2020-06-02 13:46:53 -07:00
parent 8668e2348e
commit 49fa1cf8df
1 changed files with 13 additions and 4 deletions

View File

@ -3,6 +3,7 @@ import json
from inquisitor.configs import DUNGEON_PATH from inquisitor.configs import DUNGEON_PATH
from inquisitor import error from inquisitor import error
from inquisitor import timestamp
class WritethroughDict(): class WritethroughDict():
"""A wrapper for a dictionary saved to the disk.""" """A wrapper for a dictionary saved to the disk."""
@ -57,7 +58,7 @@ def load_items(source_name):
path = os.path.join(cell_path, filename) path = os.path.join(cell_path, filename)
item = WritethroughDict(path) item = WritethroughDict(path)
items[item['id']] = item items[item['id']] = item
except Exception as e: except Exception:
errors.append(filename) errors.append(filename)
return items, errors return items, errors
@ -67,6 +68,7 @@ def load_active_items():
""" """
items = [] items = []
errors = [] errors = []
now = timestamp.now()
for cell_name in os.listdir(DUNGEON_PATH): for cell_name in os.listdir(DUNGEON_PATH):
cell_path = os.path.join(DUNGEON_PATH, cell_name) cell_path = os.path.join(DUNGEON_PATH, cell_name)
for filename in os.listdir(cell_path): for filename in os.listdir(cell_path):
@ -74,8 +76,15 @@ def load_active_items():
try: try:
path = os.path.join(cell_path, filename) path = os.path.join(cell_path, filename)
item = WritethroughDict(path) item = WritethroughDict(path)
if item['active']: # The time-to-show field hides items until an expiry date.
items.append(item) if 'tts' in item:
except Exception as e: tts_date = item['created'] + item['tts']
if now < tts_date:
continue
# Don't show inactive items
if not item['active']:
continue
items.append(item)
except Exception:
errors.append(filename) errors.append(filename)
return items, errors return items, errors