Administrator
2022-10-21 892b50e242e3c59a738b92dfdfee1bf1ff8932f2
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
import time
 
import pygame
 
 
# 报警
import tool
 
 
def alarm():
    if not tool.is_trade_time():
        return
    # TODO 暂时关闭报警
    # AlertUtil().stop_audio()
    # AlertUtil().play_audio()
 
 
class AlertUtil:
    __instance = None
 
    # 单例模式
    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
            cls.__instance = super(AlertUtil, cls).__new__(cls, *args, **kwargs)
            # 初始化设置
            pygame.mixer.init()
            pygame.mixer.music.load('alert.mp3')
            pygame.mixer.music.set_volume(1)
        return cls.__instance
 
    def play_audio(self):
        pygame.mixer.music.play()
 
    def stop_audio(self):
        pygame.mixer.music.stop()
 
 
if __name__ == '__main__':
    alarm()
    time.sleep(2)