summaryrefslogtreecommitdiff
path: root/main.py
blob: fce26f6ee0e72366b6157ae24191633fa1fcb964 (plain)
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
import pygal
import csv
import time
import datetime
import hashlib
from collections import OrderedDict
import inputs
import formatting as f

print("welcome to lock-n-log, the best way to organise and analyse your focus time!")

print("tag for session? ", end="", flush=True)
tag = input()
if tag == "":
    tag = "work"

valid_timer_types = ('t', 's')
option = False
while not option:
    print("(t)imer or (s)topwatch? ", end="", flush=True)
    option = inputs.get_valid_char(valid_timer_types)
    print("")

if option == 't':
    print("timer length (in minutes)? ", end="", flush=True)
    timer_length = inputs.get_pos_int()
    while not timer_length:
        print("please enter a positive integer")
        print("timer length (in minutes)? ", end="", flush=True)
        timer_length = inputs.get_pos_int()

    # need timer to be accurate; sleep until next second start? processing time
    # although small will still add to time so needs to be avoided
    # timer loop
    time_left = timer_length #* 60
    time_start = time.time()
    while time_left:
        # see https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
        print("\x1b[2K\r" + f.sec_to_min(time_left), end="", flush=True)
        time_left -= 1
        time.sleep(1)

    print("\nfocus session finished!\nlogging...")
    session = OrderedDict()
    session["id"] = hashlib.sha256(str(time_start).encode('utf8')).hexdigest()
    session["date"] = time.strftime("%Y-%m-%d")
    session["start"] = time.strftime("%H:%M")
    session["elapsed"] = timer_length * 60
    session["type"] = "focus"
    session["tag"] = tag
    session["timer"] = "timer"
    session["ratio"] = 0.2
    #print(session)

    f.sess_to_log(session, "lock-n-log.csv")