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)
|