Skip to content

Commit

Permalink
Add new simpler scheduling #1
Browse files Browse the repository at this point in the history
  • Loading branch information
gurland committed Jun 24, 2018
1 parent a175ca9 commit 3e9ed88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
10 changes: 3 additions & 7 deletions algebrach.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import config
from commands import arxiv_queries, dice, me, morning_message, wiki, wolfram, kek
from utils import dp, command_with_delay, commands_handler, scheduler, action_log, user_action_log
from utils import dp, command_with_delay, commands_handler, action_log, user_action_log, loop, my_bot


logging.basicConfig(level=logging.INFO,
Expand Down Expand Up @@ -130,10 +130,6 @@ async def my_kek(message):
else:
action_log("Running bot!")

scheduler.add_job(morning_message.morning_msg, 'cron', id='morning_msg', replace_existing=True, hour=7,
timezone=pytz.timezone('Europe/Moscow'))
dp.loop.create_task(morning_message.schedule_morning_messages())
executor.start_polling(dp, skip_updates=True)

scheduler.add_job(morning_message.unpin_msg, 'cron', id='unpin_msg', replace_existing=True, hour=13,
timezone=pytz.timezone('Europe/Moscow'))

executor.start_polling(dp)
17 changes: 17 additions & 0 deletions commands/morning_message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import datetime
import random
import asyncio

import bs4
import pytz
Expand Down Expand Up @@ -45,6 +46,7 @@ async def morning_msg():
now = datetime.datetime.now(pytz.timezone('Europe/Moscow'))

people_in_chat = await my_bot.get_chat_members_count(config.mm_chat)
print(people_in_chat)

text += 'Сегодня *{} {}*, *{}*. Нас в чате *{}*!'.format(now.day, month_names[now.month - 1],
weekday_names[now.weekday()],
Expand All @@ -67,3 +69,18 @@ async def unpin_msg():
if message is not None:
if message.from_user.is_bot is True:
await my_bot.unpin_chat_message(config.mm_chat)


async def schedule_morning_messages():
while True:
now = datetime.datetime.now(pytz.timezone('Europe/Moscow'))

if now.hour == 3 and now.minute == 43:
await morning_msg()
await asyncio.sleep(60)

elif now.hour == 3 and now.minute == 45:
await unpin_msg()
await asyncio.sleep(60)

await asyncio.sleep(10)

0 comments on commit 3e9ed88

Please sign in to comment.