<commit_before>import datetime
import threading
import pygame
import os

#only one clock at a moment
_clock = None
_running = False

pygame.mixer.init()
# alarm sound from http://www.orangefreesounds.com/
pygame.mixer.music.load(os.path.abspath("alarm.wav"))

def turn_off():
    pygame.mixer.music.stop()
    _running = False
    _clock = None

def set_alarm(date):
    if(_clock is not None):
        return "there is already an alarm going on"
    time = datetime.datetime.strptime(date,"%H:%M")
    clock = Clock()
    clock.set_alarm(time.hour, time.minute)
    clock.run()

def set_countdown(milis):
    if(_clock is not None):
        return "there is already an alarm going on"
    time = datetime.datetime.now() + datetime.timedelta(milliseconds=milis)
    clock = Clock()
    clock.set_alarm(time.hour, time.minute)
    clock.run()

def ring_ring():
    _running = True
    pygame.mixer.music.play(loops=-1)

def is_running():
    return _running

class Clock:

    def __init__(self):
        self.alarm_time = None
        self._alarm_thread = None
        self.update_interval = 1
        self.event = threading.Event()

    def run(self):
        while True:
            self.event.wait(self.update_interval)
            if self.event.isSet():
                break
            now = datetime.datetime.now()
            #if self._alarm_thread and self._alarm_thread.is_alive():
            #    alarm_symbol = '+'
            # else:
            #    alarm_symbol = ' '
            #sys.stdout.write("\r%02d:%02d:%02d %s"
            #    % (now.hour, now.minute, now.second, alarm_symbol))
            #sys.stdout.flush()
            #TODO show remaining time on display

    def set_alarm(self, hour, minute):
        now = datetime.datetime.now()
        alarm = now.replace(hour=int(hour), minute=int(minute))
        delta = int((alarm - now).total_seconds())
        if delta <= 0:
            alarm = alarm.replace(day=alarm.day + 1)
            delta = int((alarm - now).total_seconds())
        if self._alarm_thread:
            self._alarm_thread.cancel()
        self._alarm_thread = threading.Timer(delta, ring_ring)
        self._alarm_thread.daemon = True
        self._alarm_thread.start()
<commit_msg>pygame mixer update<commit_after>import datetime
import threading
import pygame
import os

#only one clock at a moment
_clock = None
_running = False

pygame.mixer.init()
# alarm sound from http://www.orangefreesounds.com/
pygame.mixer.music.load(os.path.abspath(r"audio\alarm.wav"))

def turn_off():
    pygame.mixer.music.stop()
    _running = False
    _clock = None

def set_alarm(date):
    if(_clock is not None):
        return "there is already an alarm going on"
    time = datetime.datetime.strptime(date,"%H:%M")
    clock = Clock()
    clock.set_alarm(time.hour, time.minute)
    clock.run()

def set_countdown(milis):
    if(_clock is not None):
        return "there is already an alarm going on"
    time = datetime.datetime.now() + datetime.timedelta(milliseconds=milis)
    clock = Clock()
    clock.set_alarm(time.hour, time.minute)
    clock.run()

def ring_ring():
    _running = True
    pygame.mixer.music.play(loops=-1)

def is_running():
    return _running

class Clock:

    def __init__(self):
        self.alarm_time = None
        self._alarm_thread = None
        self.update_interval = 1
        self.event = threading.Event()

    def run(self):
        while True:
            self.event.wait(self.update_interval)
            if self.event.isSet():
                break
            now = datetime.datetime.now()
            #if self._alarm_thread and self._alarm_thread.is_alive():
            #    alarm_symbol = '+'
            # else:
            #    alarm_symbol = ' '
            #sys.stdout.write("\r%02d:%02d:%02d %s"
            #    % (now.hour, now.minute, now.second, alarm_symbol))
            #sys.stdout.flush()
            #TODO show remaining time on display

    def set_alarm(self, hour, minute):
        now = datetime.datetime.now()
        alarm = now.replace(hour=int(hour), minute=int(minute))
        delta = int((alarm - now).total_seconds())
        if delta <= 0:
            alarm = alarm.replace(day=alarm.day + 1)
            delta = int((alarm - now).total_seconds())
        if self._alarm_thread:
            self._alarm_thread.cancel()
        self._alarm_thread = threading.Timer(delta, ring_ring)
        self._alarm_thread.daemon = True
        self._alarm_thread.start()

{'fraction_non_alphanumeric': 0.11815948179584543, 'fraction_numerical': 0.004467277194549922, 'mean_word_length': 2.3517964071856285, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6938590', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1423, 'n_words': 312}