STATE_PATH env variable

This commit is contained in:
Tomáš Mládek 2021-02-27 10:44:15 +01:00
parent b992f37663
commit f78d5e414d

6
bot.py
View file

@ -15,6 +15,8 @@ from config import Config
config = Config()
config.WEBHOOK_URL = os.getenv("WEBHOOK_URL", config.WEBHOOK_URL)
STATE_PATH = os.getenv("STATE_PATH", "state.pickle")
class State:
notified = []
@ -74,7 +76,7 @@ async def send_message(text):
async def main():
try:
with open('state.pickle', 'rb') as state_fp:
with open(STATE_PATH, 'rb') as state_fp:
state = pickle.load(state_fp)
except FileNotFoundError:
state = State()
@ -101,7 +103,7 @@ async def main():
await send_message(process_event(event, config.SOON_TEMPLATE))
state.notified_soon.append(event.name)
with open('state.pickle', 'wb') as state_fp:
with open(STATE_PATH, 'wb') as state_fp:
pickle.dump(state, state_fp)
logging.debug("Sleeping for 60s...")