Пример #1
0
def receive_picture_alert(sender, **kwargs):
    event=kwargs['data']
    from motioncontrol.models import AlertSubscription
    als = AlertSubscription.objects.filter(cam=event.cam,enabled=True,alert_motion=True,pause=False)
    for a in als:
        if a.channel == 'telegram':
            from telegrambot.wrapper import Bot
            img = event.img()
            if img:
                b = Bot(settings.TELEGRAM_BOT_TOKEN)
                fp = BytesIO()
                img.save(fp,'JPEG')
                fp.seek(0)            
                b.sendPhoto(a.destination, fp, caption='motion alert %s' % event.cam.name)
                #cache.set("%s-%s-%s" % (__name__,tipo,self.user.user_id),True,30)    

    print("Picture Alert")
Пример #2
0
    def sendAlert(self,event,tipo):
        from telegrambot.wrapper import Bot
        if tipo == 'motion':
            if not cache.get("%s-%s-%s" % (__name__,tipo,self.user.user_id)):
                b = Bot(settings.TELEGRAM_BOT_TOKEN)
                fp = BytesIO()
                event.snapshot().save(fp,'JPEG')
                fp.seek(0)            
                b.sendPhoto(self.user.user_id, fp, caption='motion alert %s' % self.camera.name)
                cache.set("%s-%s-%s" % (__name__,tipo,self.user),True,30)

        if tipo == 'picture':
            img = event.img()
            if img:
                if not cache.get("%s-%s-%s" % (__name__,tipo,self.user.user_id)):
                    b = Bot(settings.TELEGRAM_BOT_TOKEN)
                    fp = BytesIO()
                    event.img().save(fp,'JPEG')
                    fp.seek(0)            
                    b.sendPhoto(self.user.user_id, fp, caption='picture alert %s' % self.camera.name)
                    cache.set("%s-%s-%s" % (__name__,tipo,self.user.user_id),True,30)