Ejemplo n.º 1
0
async def reg(chat: Chat, match):
    # TODO return back or add password protect
    return
    async with db_in_thread():
        admin = db.query(Admin).filter(Admin.chat_id == chat.id).one_or_none()
    if admin:
        await chat.send_text('You are already registered!')
        return
    async with db_in_thread():
        admin = Admin(chat_id=chat.id)
        db.add(admin)
        db.commit()
    await chat.send_text('You are successfully registered!')
Ejemplo n.º 2
0
 async def daily_movie(self, cam: Cam):
     day = datetime.datetime.now() - datetime.timedelta(days=1)
     day = day.strftime('%d_%m_%Y')
     loop = asyncio.get_event_loop()
     with concurrent.futures.ThreadPoolExecutor() as pool:
         try:
             clip = await loop.run_in_executor(pool,
                                               lambda: make_movie(cam, day))
         except FileNotFoundError as exc:
             logger.exception(exc)
             await self.notify_admins(
                 f'File {exc.filename} not found for daily movie {cam.name}: {day}'
             )
             return
         except Exception as exc:
             logger.exception(exc)
             await self.notify_admins(
                 f'Error during making daily movie for {cam.name}: {day}')
             return
     if cam.update_channel:
         async with db_in_thread():
             channels = db.query(Channel).filter(
                 Channel.cam == cam.name).all()
         for channel in channels:
             await send_video(Chat(self._bot, channel.chat_id), clip)
     await self.notify_admins(f'Daily movie for {cam.name}: {day} ready!')
     for chat in await self.admin_chats():
         await send_video(Chat(self._bot, chat.chat_id), clip)
Ejemplo n.º 3
0
 async def _post_photo(self, cam: Cam, photo: Path):
     async with db_in_thread():
         channels = db.query(PhotoChannel).filter(
             PhotoChannel.cam == cam.name).all()
     for channel in channels:
         chat = Chat(self._bot, channel.chat_id)
         with open(photo, 'rb') as ph:
             await chat.send_photo(ph)
Ejemplo n.º 4
0
 async def choose_cam_callback(self, chat, cq, match):
     cam = match.group(1)
     async with db_in_thread():
         channel = Channel(chat_id=chat.id, cam=cam)
         db.add(channel)
         db.commit()
     await cq.answer(text=f'Added channel for {cam}')
     await self.notify_admins(text=f'Added channel {chat.id} for {cam}')
Ejemplo n.º 5
0
 async def reg_channel(self, chat: Chat, match):
     async with db_in_thread():
         channel = db.query(Channel).filter(
             Channel.chat_id == chat.id).one_or_none()
     if channel:
         await self.notify_admins(f'Channel {chat.id} already registered!')
         return
     await chat.send_text('Choose cam for channel',
                          reply_markup=CamerasChannel().options.to_json())
Ejemplo n.º 6
0
 async def db_data(self, chat: Chat, match):
     async with db_in_thread():
         md_data = db_data()
     await chat.send_text('\n'.join(md_data), parse_mode='Markdown')
Ejemplo n.º 7
0
 async def admin_chats(self):
     async with db_in_thread():
         return db.query(Admin).all()
Ejemplo n.º 8
0
 async def notify_admins(self, text, **options):
     async with db_in_thread():
         admins = db.query(Admin).all()
     for admin in admins:
         await self._bot.send_message(admin.chat_id, text, **options)