Repository navigation
Expand file tree
/
Copy pathnotify.py
More file actions
67 lines (48 loc) · 2.09 KB
/
Copy pathnotify.py
File metadata and controls
67 lines (48 loc) · 2.09 KB
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
from config import Config
from sound import Sound
from log import Log
import time
class Notify:
def __init__( self, config: Config ):
self.config = config
self.sound = Sound( self.config )
self.outages_total = 0
self.outage_current_time = 0
self.outages_total_time = 0
self.active_total_time = 0
self.active_current_time = 0
self.sound.create_audio_files()
def active( self ) -> None:
print("Internet is active")
self.active_current_time = time.time()
if self.outage_current_time:
current_outage_seconds = time.time() - self.outage_current_time
self.outages_total_time += current_outage_seconds
print(f"Down for {current_outage_seconds}s")
outage_average = self.outages_total_time / self.outages_total
print(f"Total outages: {self.outages_total}, Average downtime: {outage_average}s")
if self.config.NOTIFY_ACTIVE_VOICE:
self.sound.play(self.config.ACTIVE_FILE)
def down( self ) -> None:
print("Internet is down")
self.outages_total += 1
self.outage_current_time = time.time()
if self.active_current_time:
current_active_seconds = time.time() - self.active_current_time
self.active_total_time += current_active_seconds
print(f"Up for {current_active_seconds}s")
active_average = self.active_total_time / self.outages_total
print(f"Total uptime: {self.active_total_time}s, Average uptime: {active_average}s")
if self.config.NOTIFY_ACTIVE_VOICE:
self.sound.play(self.config.DOWN_FILE)
def speed_slow( self ) -> None:
print("Internet is slow")
if self.config.NOTIFY_LATENCY_VOICE:
self.sound.play(self.config.SLOW_FILE)
def speed_normal( self ) -> None:
print("Internet speed is normal")
if self.config.NOTIFY_LATENCY_VOICE:
self.sound.play(self.config.NORMAL_FILE)
def latency( self ) -> None:
if self.config.NOTIFY_LATENCY_BEEP:
self.sound.blip()