コード例 #1
0
def main():
    global start_of_event
    global last_window
    global last_event
    global html_update_time

    analytic = Analytics()

    print("""
---------------------------------------
TRACK YOUR TIME - DON'T WASTE IT!
---------------------------------------

  TIME           CATEGORY""")

    while True:
        mouse_idle = is_mouse_idle()
        keyboard_idle = is_keyboard_idle(0.01)

        current_window = get_window_name()
        idle = mouse_idle and keyboard_idle

        if idle:
            current_event = 'idle'
        else:
            current_event = current_window

        if current_event != last_event:
            if last_event == 'idle':
                category = 'idle'
            else:
                category = analytic.get_cat(last_window)

            duration = time.time() - start_of_event
            if duration > 2:

                save_data([time.time(), category, int(duration)])
                try:
                    if sys.version_info.major > 2:
                        mins = int(np.floor(duration / 60))
                        secs = int(np.floor(duration - mins * 60))
                        print("{0: 3}:{1:02} min\t".format(mins, secs),
                              "{}\t".format(category),
                              "({})".format(last_event[:30]))
                except UnicodeDecodeError:
                    print("{0: 5.0f} s\t".format(duration),
                          "UNICODE DECODE ERROR")

            last_window = current_window
            start_of_event = time.time()
            last_event = current_event

        if time.time() > html_update_time:
            analytic.create_html()
            html_update_time = time.time() + 60