-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalertbuzzer.py
executable file
·77 lines (69 loc) · 2.26 KB
/
alertbuzzer.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import time
import redis
import sys
import signal
import logging
import buzzer
logfile = '/var/log/alertringer.log'
debug = True
logger = logging.getLogger("buzzer")
logger.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler = logging.FileHandler(logfile)
handler.setFormatter(formatter)
logger.addHandler(handler)
def signal_handler(signal, frame):
logger.info('shutting down')
buzzer.destroy()
exit()
if __name__ == '__main__':
buzzer.setup()
firstrun = True
logger.info('starting up')
signal.signal(signal.SIGTERM, signal_handler)
r = redis.StrictRedis(host='localhost', port=6379, db=0)
teams = {'access': 0, 'wifi': 0, 'core': 0, 'powerpatrol': 0, 'services': 0}
while True:
time.sleep(1)
oldteams = teams.copy()
teams = {'access': 0, 'wifi': 0, 'core': 0, 'powerpatrol': 0, 'services': 0}
for key in r.scan_iter():
val = r.get(key)
if val is None:
if debug:
print(key)
else:
team = json.loads(val.decode('utf-8'))['team']
teams[team] = teams[team] +1
if firstrun == True:
firstrun = False
continue
if teams != oldteams:
if teams['services'] > oldteams['services']:
logger.info('playing services')
firstrun = True
buzzer.play(buzzer.popcorn_melody, buzzer.popcorn_tempo, 0.50, 1.000)
continue
if teams['core'] > oldteams['core']:
logger.info('playing core')
firstrun = True
buzzer.play(buzzer.star_wars_melody, buzzer.star_wars_tempo, 0.50, 1.000)
continue
if teams['access'] > oldteams['access']:
logger.info('playing access')
firstrun = True
buzzer.play(buzzer.crazy_frog_melody, buzzer.crazy_frog_tempo, 0.30, 0.900)
continue
if teams['wifi'] > oldteams['wifi']:
logger.info('playing wifi')
firstrun = True
buzzer.play(super_mario_melody, super_mario_tempo, 1.3, 0.800)
continue
if teams['powerpatrol'] > oldteams['powerpatrol']:
logger.info('playing powerpatrol')
firstrun = True
buzzer.play(buzzer.final_countdown_melody, buzzer.final_countdown_tempo, 0.30, 1.1000)
continue