Fix exception when no orders given
Message on Telegram when no orders given
This commit is contained in:
parent
16af4ab110
commit
cec2a56ec0
2 changed files with 24 additions and 16 deletions
29
orders.py
29
orders.py
|
|
@ -12,22 +12,28 @@ from util import timezone
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def order_mastodon_post(session, orders_str, repeats, due_at):
|
||||
m_post = "Here are today's orders for @%s -\n\n" % MASTODON_USERNAME
|
||||
m_post += orders_str + "\n\n"
|
||||
post = "Here are today's orders for @%s -\n\n" % MASTODON_USERNAME
|
||||
post += orders_str + "\n\n"
|
||||
if repeats > 1:
|
||||
m_post += f"These are the same orders from the last {repeats} days\n\n"
|
||||
m_post += "Proof of compliance is due by " + due_at.strftime("%H:%M %p")
|
||||
post += f"These are the same orders from the last {repeats} days\n\n"
|
||||
post += "Proof of compliance is due by " + due_at.strftime("%H:%M %p")
|
||||
|
||||
m = Mastodon(session)
|
||||
return await m.statusPost(m_post)
|
||||
return await m.statusPost(post)
|
||||
|
||||
async def order_telegram_post(session, orders_str, repeats, due_at, m_url):
|
||||
t_post = "Here are your orders -\n\n"
|
||||
t_post += orders_str + "\n\n"
|
||||
post = "Here are your orders -\n\n"
|
||||
post += orders_str + "\n\n"
|
||||
if repeats > 1:
|
||||
t_post += f"These are the same orders from the last {repeats} days\n\n"
|
||||
t_post += "Proof of compliance is due by " + due_at.strftime("%H:%M %p") + "\n\n"
|
||||
t_post += m_url
|
||||
post += f"These are the same orders from the last {repeats} days\n\n"
|
||||
post += "Proof of compliance is due by " + due_at.strftime("%H:%M %p") + "\n\n"
|
||||
post += m_url
|
||||
|
||||
t = Telegram(session)
|
||||
await t.message_send(post)
|
||||
|
||||
async def order_telegram_post_none(session):
|
||||
t_post = "No orders for today"
|
||||
|
||||
t = Telegram(session)
|
||||
await t.message_send(t_post)
|
||||
|
|
@ -36,8 +42,9 @@ async def order_issue():
|
|||
async with make_session() as session:
|
||||
orders_info = generate_order()
|
||||
|
||||
if 'orders' not in orders_info:
|
||||
if 'orders' not in orders_info or True:
|
||||
logger.info("No orders for today")
|
||||
await order_telegram_post_none(session)
|
||||
return
|
||||
|
||||
orders_str = "\n".join(orders_info['orders'])
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class OrderScheduler():
|
|||
|
||||
due_at = await order_issue()
|
||||
|
||||
if due_at is not None:
|
||||
# Schedule check
|
||||
self.scheduler.once(
|
||||
due_at + GRACE_PERIOD,
|
||||
|
|
|
|||
Loading…
Reference in a new issue