forked from Va5c0/Raspberry-Telegram-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarm.py
38 lines (30 loc) · 895 Bytes
/
alarm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import telebot
import sys
import pygame
import time
import os
TOKEN = "TOKEN" # Cambiar por el token
cid = "Nº CID" # Cambiar por el numero cid
bot = telebot.TeleBot(TOKEN)
def play(fname, seg):
pygame.mixer.init()
pygame.mixer.init(44100)
pygame.mixer.music.load(fname)
pygame.mixer.music.play()
time.sleep(seg)
pygame.mixer.music.stop()
if len(sys.argv) < 2:
print("Uso: %s [cam/move]" % sys.argv[0])
elif sys.argv[1] == "cam":
bot.send_message(cid, "¡¡Camara no disponible!!")
elif sys.argv[1] == "move":
bot.send_message(cid, "¡¡Movimiento Detectado!!")
with open('alarm.txt', 'r') as f:
state = f.readline().strip('\n')
if state == "1":
play('Sonidos/alarma.mp3', 15)
os.system('espeak -ves+m7 -s165 -p30 \"Intruso detectado\"')
else:
print(" ¡¡ERROR!!")