STATE_PATH env variable
This commit is contained in:
parent
b992f37663
commit
f78d5e414d
1 changed files with 4 additions and 2 deletions
6
bot.py
6
bot.py
|
@ -15,6 +15,8 @@ from config import Config
|
||||||
config = Config()
|
config = Config()
|
||||||
config.WEBHOOK_URL = os.getenv("WEBHOOK_URL", config.WEBHOOK_URL)
|
config.WEBHOOK_URL = os.getenv("WEBHOOK_URL", config.WEBHOOK_URL)
|
||||||
|
|
||||||
|
STATE_PATH = os.getenv("STATE_PATH", "state.pickle")
|
||||||
|
|
||||||
|
|
||||||
class State:
|
class State:
|
||||||
notified = []
|
notified = []
|
||||||
|
@ -74,7 +76,7 @@ async def send_message(text):
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
try:
|
try:
|
||||||
with open('state.pickle', 'rb') as state_fp:
|
with open(STATE_PATH, 'rb') as state_fp:
|
||||||
state = pickle.load(state_fp)
|
state = pickle.load(state_fp)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
state = State()
|
state = State()
|
||||||
|
@ -101,7 +103,7 @@ async def main():
|
||||||
await send_message(process_event(event, config.SOON_TEMPLATE))
|
await send_message(process_event(event, config.SOON_TEMPLATE))
|
||||||
state.notified_soon.append(event.name)
|
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)
|
pickle.dump(state, state_fp)
|
||||||
|
|
||||||
logging.debug("Sleeping for 60s...")
|
logging.debug("Sleeping for 60s...")
|
||||||
|
|
Loading…
Reference in a new issue