aboutsummaryrefslogtreecommitdiff
path: root/src/Watcher/commands.py
blob: dd1d2c4157e8138029538e42f972cbcdc8ce94cd (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import csv
import datetime
from watch_log import get_date
import analysis as anls
import time_operations as to

class Color:

    def GREY(text):
        return '\033[90m' + text + '\033[0m'

    def BLUE(text):
        return '\033[34m' + text + '\033[0m'

    def GREEN(text):
        return '\033[32m' + text + '\033[0m'

    def YELLOW(text):
        return '\033[33m' + text + '\033[0m'

    def RED(text):
        return '\033[31m' + text + '\033[0m'

    def PURPLE(text):
        return '\033[35m' + text + '\033[0m'

    def DARKCYAN(text):
        return '\033[36m' + text + '\033[0m'

    def BOLD(text):
        return '\033[1m' + text + '\033[0m'

    def UNDERLINE(text):
        return '\033[4m' + text + '\033[0m'


def daily_summary():
    date = get_date()
    window_opened, time_spent = anls.extract_data(date)
    Total_screen_time = "00:00:00"
    for x,y in anls.final_report(window_opened, time_spent).items():
        Total_screen_time = to.time_addition(y, Total_screen_time)

    if len(to.format_time(Total_screen_time)) == 3:
        print(Color.YELLOW("\n   Today's Screen-Time\t\t   ") + Color.BLUE(f'{to.format_time(Total_screen_time):>16}'))
    elif len(to.format_time(Total_screen_time)) == 7:
        print(Color.YELLOW("\n   Today's Screen-Time\t\t   ") + Color.BLUE(f'{to.format_time(Total_screen_time):>11}'))
    elif len(to.format_time(Total_screen_time)) == 11:
            print(Color.YELLOW("\n   Today's Screen-Time\t\t   ") + Color.BLUE(to.format_time(Total_screen_time)))

    print(" ────────────────────────────────────────────────")
    print(Color.RED(f'{" App Usages":>29}'))
    print(" ────────────────────────────────────────────────")

    for x,y in anls.final_report(window_opened, time_spent).items():
        if x == "":
            x = "Home-Screen"
        print("   " + Color.GREEN(f'{x:<22}') + '\t ',f'{to.format_time(y):>12}')

def week_summary():
    W_Y = os.popen('''date +"W%V-%Y"''').read()[0:-1]
    user = os.getlogin()
    filename = "/home/"+user+"/.cache/Watcher/Analysis/"+W_Y+".csv"
    with open(filename, 'r') as file:
        csvreader = csv.reader(file, delimiter='\t')
        week_overview = dict()
        app_usages = dict()
        for row in csvreader:
            if len(row[0]) == 3:
                week_overview.update({row[0]:row[1]}) # Weekday -- screen-time
            else:
                app_usages.update({row[1]:row[0]}) # app-name -- usage

    week_screen_time = "00:00:00"
    for x, y in week_overview.items():
        week_screen_time = to.time_addition(y, week_screen_time)

    print(Color.PURPLE("\n   Week's screen-time\t\t   ") + Color.BLUE(to.format_time(week_screen_time)))
    print(" ────────────────────────────────────────────────")

    for x, y in week_overview.items():
        print("  " + f'{Color.YELLOW(x):>21}' + "\t\t   " + Color.BLUE(to.format_time(y)))

    #anls.prints_report(window_opened, time_spent, is_week)
    print(" ────────────────────────────────────────────────")
    print(Color.RED(f'{" App Usages":>29}'))
    print(" ────────────────────────────────────────────────")
    for x,y in app_usages.items():
        if x == "":
            x = "Home-Screen"
        print("   " + Color.GREEN(f'{x:<22}') + '\t ',f'{to.format_time(y):>12}')

if __name__ == "__main__":
    week_summary()