From af16350b30a9f02974ddc880ee51bf475cb150f8 Mon Sep 17 00:00:00 2001 From: Waishnav Date: Tue, 22 Mar 2022 16:38:11 +0530 Subject: improvised append_line function --- src/Watcher/watch_log.py | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/Watcher/watch_log.py b/src/Watcher/watch_log.py index 1359ecc..2bf5b9f 100755 --- a/src/Watcher/watch_log.py +++ b/src/Watcher/watch_log.py @@ -14,13 +14,12 @@ def get_date(): d = os.popen('''date +"%Y-%m-%d"''').read() return d[0:-1] -def append_line_in_csv(date, closed_time, window_name): +def append_line_in_csv(date, opened_time, closed_time, window_name): user = os.getlogin() filename = "/home/"+user+"/.cache/Watcher/raw_data/"+date+".csv" - with open(filename, 'r') as file: - last_app_time = file.readlines()[-1][0:8] - - time_spent = time_difference(last_app_time, closed_time) +# with open(filename, 'r') as file: +# last_app_time = file.readlines()[-1][0:8] + time_spent = time_difference(opened_time, closed_time) Data = [closed_time, time_spent, window_name] with open(filename, 'a') as csvfile: @@ -41,27 +40,20 @@ def log_creation(): with open(filename, 'a') as csvfile: csvwriter = csv.writer(csvfile, delimiter='\t') csvwriter.writerow([get_time(), "00:00:00", ""]) - append_line_in_csv(get_date(), get_time(), "User-logged-in") + + # appending line at login + with open(filename, 'r') as file: + logged_out_time = file.readlines()[-1][0:8] + append_line_in_csv(get_date(), logged_out_time, get_time(), "User-logged-in") while True: + opened_at = get_time() previous_window = x.active_window() if x.is_window_changed(previous_window) and not(afk): next_window = x.active_window() closed_at = get_time() # for next_window its the opening time date = get_date() - filename = "/home/"+os.getlogin()+"/.cache/Watcher/raw_data/"+date+".csv" - if not(os.path.isfile(filename)): - with open(filename, 'a') as csvfile: - csvwriter = csv.writer(csvfile, delimiter='\t') - prev_date = os.popen("""date -d "yesterday" '+%Y-%m-%d'""").read()[0:-1] - prev_file = "/home/"+os.getlogin()+"/.cache/Watcher/raw_data/"+prev_date+".csv" - with open(prev_file, 'r') as file: - last_app_time = file.readlines()[-1][0:8] - csvwriter.writerow([get_time(), time_difference(last_app_time, closed_at), previous_window]) - - else: - # appends line when app gets closed - append_line_in_csv(date, closed_at, previous_window) + append_line_in_csv(date, opened_at, closed_at, previous_window) if afk: afk_closed_time = get_time() -- cgit v1.2.3 From 471d0b43e3fa2f5f077ce9ad4824992058d26e0e Mon Sep 17 00:00:00 2001 From: Waishnav Date: Fri, 8 Jul 2022 20:23:17 +0530 Subject: updating log file algorithm | added AFK feature | changing dependency xdotool to ewmh --- src/Watcher/afk.py | 14 +++++++++++ src/Watcher/get_windows.py | 62 +++++++++++++++++++++++++--------------------- src/Watcher/watch_log.py | 54 +++++++++++++++++++++------------------- 3 files changed, 76 insertions(+), 54 deletions(-) diff --git a/src/Watcher/afk.py b/src/Watcher/afk.py index e69de29..2c54888 100755 --- a/src/Watcher/afk.py +++ b/src/Watcher/afk.py @@ -0,0 +1,14 @@ +import os +def IsAFK(): + time_since_last_input = int(os.popen("xprintidle").read()) + if time_since_last_input >= 3000: + video_playback = os.popen("""pacmd list-sink-inputs | grep -w state | grep -i 'CORKED'""").read() + # if playback is not running as well as user is AFK + if "CORKED" in video_playback: + return True + # if playback is running is background as well as user is AFK + else: + return False + else: + return False + diff --git a/src/Watcher/get_windows.py b/src/Watcher/get_windows.py index 6b1960f..393c7ff 100755 --- a/src/Watcher/get_windows.py +++ b/src/Watcher/get_windows.py @@ -1,49 +1,55 @@ import os import time +from ewmh import EWMH class window: def __init__(self, class_name, title_name): self.class_name = class_name self.title_name = title_name -# get classname of app that user working on -def active_window(): - # running bash command and storing result as a string - active_window = os.popen("xdotool getwindowfocus getwindowclassname").read() - active_window = active_window[0:-1] - return active_window - # get title name of app that user working on def active_window_title(): - active_window_title = os.popen("xdotool getwindowfocus getwindowname").read() - active_window_title = active_window_title[0:-1] + try: + win = EWMH().getActiveWindow() + active_window_title = win.get_wm_name() + except AttributeError: + active_window_title = "unknown" + active_window_title = active_window_title.capitalize() return active_window_title -# get list of opened apps in background as well as in foreground -def opened_windows_list(): - raw_data = os.popen('''wmctrl -lx | awk '{print $3}' ''').read() - raw_data_ls = raw_data.split('\n') - windows_list = [] - for x in raw_data_ls: - last = x.rfind(".") - windows_list.append(x[last+1::]) - windows_list.remove('') - windows_list = list(set(windows_list)) - return windows_list +# get classname of app that user working on +def active_window(): + try: + win = EWMH().getActiveWindow() + active_window = win.get_wm_class()[1] + except AttributeError: + active_window = "unknown" + + if len(active_window) > 20: + active_window = "unknown" + elif "\n" in active_window: + active_window = "unknown" + active_window = active_window.capitalize() + + # check whether user is using nvim or vim + aw_title = active_window_title() + terminals = ["Kitty", "Alacritty", "Terminator", "Tilda", "Guake", "Yakuake", "Roxterm", "Eterm", "Rxvt", "Xterm", "Tilix", "Lxterminal", "Konsole", "St", "Gnome-terminal", "Xfce4-terminal", "Terminology", "Extraterm"] + if active_window in terminals: + if "Nvim" in aw_title: + active_window = "NeoVim" + elif "Vim" in aw_title: + active_window = "Vim" + return active_window # returns true if user has move to next app which is not the same as previous def is_window_changed(a): result = False - while not(result): - time.sleep(1) - b = active_window() - if a != b : - result = True - else: - result = False + time.sleep(0.1) + b = active_window() + if a != b : + result = True return result - ### what to do after window get change I've to append one line in csv data file in following format ### opened-time closed-time time-spent window_class_name window_title_name diff --git a/src/Watcher/watch_log.py b/src/Watcher/watch_log.py index 2bf5b9f..4956deb 100755 --- a/src/Watcher/watch_log.py +++ b/src/Watcher/watch_log.py @@ -2,7 +2,8 @@ import os import csv import time import get_windows as x -from time_operations import time_difference +import afk +from time_operations import time_difference, time_addition # get current time whenever the function is called def get_time(): @@ -14,27 +15,17 @@ def get_date(): d = os.popen('''date +"%Y-%m-%d"''').read() return d[0:-1] -def append_line_in_csv(date, opened_time, closed_time, window_name): +def append_line_in_csv(date, opened_time, time_spent, window_name): user = os.getlogin() filename = "/home/"+user+"/.cache/Watcher/raw_data/"+date+".csv" -# with open(filename, 'r') as file: -# last_app_time = file.readlines()[-1][0:8] - time_spent = time_difference(opened_time, closed_time) - - Data = [closed_time, time_spent, window_name] + Data = [opened_time, time_spent, window_name] with open(filename, 'a') as csvfile: csvwriter = csv.writer(csvfile, delimiter='\t') csvwriter.writerow(Data) # Expected Behaviour == if date got changed then append line in new csv file after initializing the csv file -# also if usr is AFK then append line - -# TODO: AFK feature devlopement (it will be developed after completing alpha product (after whole project up end running) -afk = False def log_creation(): - global afk - filename = "/home/"+os.getlogin()+"/.cache/Watcher/raw_data/"+get_date()+".csv" if not(os.path.isfile(filename)): with open(filename, 'a') as csvfile: @@ -42,22 +33,33 @@ def log_creation(): csvwriter.writerow([get_time(), "00:00:00", ""]) # appending line at login - with open(filename, 'r') as file: - logged_out_time = file.readlines()[-1][0:8] - append_line_in_csv(get_date(), logged_out_time, get_time(), "User-logged-in") + logged_out_time = os.popen("tail -n1 " + filename).read().split("\t")[0] + time_away_from_laptop = time_difference(logged_out_time, get_time()) + append_line_in_csv(get_date(), get_time(), time_away_from_laptop, "User-logged-in") while True: - opened_at = get_time() - previous_window = x.active_window() - if x.is_window_changed(previous_window) and not(afk): - next_window = x.active_window() - closed_at = get_time() # for next_window its the opening time + actv_window = x.active_window() + if x.is_window_changed(actv_window): + next_actv_window = x.active_window() + date = get_date() + opened_at = get_time() + time_spent = "00:00:00" + append_line_in_csv(date, opened_at, time_spent, next_actv_window) + + else: date = get_date() - append_line_in_csv(date, opened_at, closed_at, previous_window) + now = get_time() # for next_window its the opening time + last_line = os.popen("tail -n1 " + filename).read().split("\t") + opened_at = last_line[0] + os.popen("""sed -i -e '$ d' """ + filename) + time.sleep(0.2) + time_spnt = time_difference(opened_at, get_time()) - if afk: - afk_closed_time = get_time() - append_line_in_csv(date, afk_closed_time, "AFK") + if afk.IsAFK(): + append_line_in_csv(date, opened_time, time_spent, "AFK") + else: + append_line_in_csv(date, opened_at, time_spnt, actv_window) if __name__ == "__main__": - log_creation() + opened_at = os.popen("""tail -n1 ~/.cache/Watcher/raw_data/2022-07-07.csv""").read().split("\t")[1] + print(opened_at) -- cgit v1.2.3 From fc1c852d9263fc43f27792f38a8e68674e944629 Mon Sep 17 00:00:00 2001 From: Waishnav Date: Fri, 8 Jul 2022 21:37:57 +0530 Subject: updating install | updating bin according to new function names --- install | 51 ++++++++++++++++++++++++--------------------------- src/bin/watcher | 7 +++---- 2 files changed, 27 insertions(+), 31 deletions(-) mode change 100755 => 100644 src/bin/watcher diff --git a/install b/install index 539e5f1..fbeb7f0 100755 --- a/install +++ b/install @@ -21,41 +21,38 @@ echo "[✔] To store raw_data making directory as ~/.cache/Watcher" mkdir -p ~/.cache/Watcher/raw_data/ mkdir -p ~/.cache/Watcher/Analysis/ -# resolving confilict with previous version of watcher -echo "[✔] Checking whether you had installed previous version of Watcher so removing those conflicts if yes" -if [ -f "$HOME/.config/systemd/user/watcher.service" ]; then - systemctl --user disable --now watcher.service - rm -rf $HOME/.config/systemd/user/watcher.service -elif [ -f "$HOME/.local/bin/watcher" ]; then - rm -rf $HOME/.local/bin/watcher -fi - # deleting folowing lines "[ -f /etc/xprofile ] && . /etc/xprofile/" and "[ -f ~/.xprofile ] && . ~/.xprofile" -sed -i '/xprofile/d' ~/.xinitrc - -# checking wherther is ~/.xprofile is sourced in ~/.xintrc or not -count1=$(grep -c "xprofile" $HOME/.xinitrc) +if [ -f "$HOME/.xinitrc" ]; +then + sed -i '/xprofile/d' ~/.xinitrc + # checking wherther is ~/.xprofile is sourced in ~/.xintrc or not + count1=$(grep -c "xprofile" $HOME/.xinitrc) +else + count1=0 +fi # checking whether user have used watcher before as well as xprofile filed setup or not -if [ -f "$HOME/.xprofile" ]; then +if [ -f "$HOME/.xprofile" ]; +then count2=$(grep -c "watcher --start" $HOME/.xprofile) else count2=0 fi -echo "[✔] Making sure that it will run at starting of each xsession afterward" - -if [ $count1 = 0 ] & [ $count2 = 0 ];then - sed -i '/bin/a \source ~/.xprofile' ~/.xinitrc - echo "killall watcher" >> $HOME/.xprofile - echo "watcher --start &" >> $HOME/.xprofile -elif [ $count1 > 0 ] & [ $count2 = 0 ];then - echo "killall watcher" >> $HOME/.xprofile - echo "watcher --start &" >> $HOME/.xprofile -elif [ $count2 > 0 ] & [ $count1 = 0 ];then - sed -i '/bin/a \source ~/.xprofile' ~/.xinitrc +echo "[✔] Making sure that it will run at startup of the system" + +if [ $count2 = 0 ]; +then + echo "watcher --start &" >> $HOME/.xprofile +fi + +if [ -f "$HOME/.xinitrc" ]; +then + if [ $count1 = 0 ] ; + then + echo "source ~/.xprofile" >> $HOME/.xinitrc + fi fi -echo "" echo "Now you can use Watcher after restart. And see you around" echo "If anything goes wrong do PR or open issue" -echo "If you wanna just give a try (without restart), You can start taking logs (run watch_log.py) by 'watcher --start' " +echo '''If you wanna just give a try (without restart), You can start taking logs (run watch_log.py) by 'watcher --start' ''' diff --git a/src/bin/watcher b/src/bin/watcher old mode 100755 new mode 100644 index 2d4551e..d2392cd --- a/src/bin/watcher +++ b/src/bin/watcher @@ -1,10 +1,9 @@ #!/usr/bin/python - import os import sys sys.path.insert(0, "/usr/share/Watcher/") import watch_log as x -from colored_text import Color +from commands import Color import commands as cmd def help_option(): @@ -23,7 +22,7 @@ try: if arg == "-ds" or arg == "--day-summary": cmd.daily_summary() elif arg == "-ws" or arg == "--week-summary": - os.popen("python3 /usr/share/Watcher/week_analysis.py") + cmd.week_summary() elif arg == "-h" or arg == "--help": help_option() @@ -31,7 +30,7 @@ try: print("Log creations started... \nif you wanna stop it, use keyboard-shortcut (Ctrl+Shift+C)") x.log_creation() elif arg == "--version": - print("Version: 1.0") + print("Version: 1.2") else: print(Color.RED("Wrong")+" [OPTION] choosen. Have a look at the Options!!\n") print(Color.YELLOW("OPTIONS")) -- cgit v1.2.3 From 7133173a8c33c8120af6006380aecf7846e6e0bd Mon Sep 17 00:00:00 2001 From: Waishnav Date: Fri, 8 Jul 2022 21:45:45 +0530 Subject: refactoring some function --- src/Watcher/analysis.py | 98 ++++++++++++++++++++++++++++++++++++++++++ src/Watcher/colored_text.py | 30 ------------- src/Watcher/commands.py | 57 +++++++++++++++++++++--- src/Watcher/report_creation.py | 82 ----------------------------------- src/Watcher/time_operations.py | 7 ++- src/Watcher/week_analysis.py | 46 -------------------- src/bin/watcher | 5 ++- 7 files changed, 156 insertions(+), 169 deletions(-) create mode 100755 src/Watcher/analysis.py delete mode 100755 src/Watcher/colored_text.py delete mode 100755 src/Watcher/report_creation.py delete mode 100755 src/Watcher/week_analysis.py diff --git a/src/Watcher/analysis.py b/src/Watcher/analysis.py new file mode 100755 index 0000000..7a96b60 --- /dev/null +++ b/src/Watcher/analysis.py @@ -0,0 +1,98 @@ +import os +import csv +from watch_log import get_date +import datetime +import time_operations as to + +def extract_data(date): + user = os.getlogin() + path = "/home/" + user +"/.cache/Watcher/raw_data/" + filename = path + date + ".csv" + + l = list() # l = list of (app_name, time spent on app on that session) + d = dict() + + if os.path.isfile(filename): + with open(filename, 'r') as file: + reader = csv.reader(file) + for row in reader: + for column in row: + l.append([column[18::],column[9:17]]) + d.update({column[18::]: "O"}) + else: + None + + d = list(d) # list of app opened on that day + return d, l + +# creating dictionary to store time spend on each applicaitons on that particular day +def final_report(window_opened, time_spent): + report = dict() + + for i in window_opened: # i is applications name + time = '00:00:00' + for j in time_spent: # j is list of applicaions_name and time_spent in particular session + if i == j[0]: + time = to.time_addition(j[1], time) + report.update({i:time}) + + #print(report) + if "User-logged-in" in report.keys(): + report.pop("User-logged-in") + # sort report dictonary in decreasing order of Usages + sorted_values = [] + for x,y in report.items(): + sorted_values.append(to.convert_into_sec(y)) + + sorted_values.sort(reverse=True) + sorted_report = dict() + + for i in sorted_values: + for x, y in report.items(): + if to.convert_into_sec(y) == i: + sorted_report.update({x:y}) + + return sorted_report + +# getting dates of the week for week summary +def get_dates(): + theday = datetime.date.today() + weekday = theday.isoweekday() - 1 + # The start of the week + start = theday - datetime.timedelta(days=weekday) + # build a simple range + dates = [start + datetime.timedelta(days=d) for d in range(weekday + 1)] + dates = [str(d) for d in dates] + + return dates + +def weekday_from_date(date): + day = os.popen('''date -d "'''+ date + '''" +%a''').read() + return day[0:-1] + +def weeklly_logs(): + 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, "w") as csvfile: + csvwriter = csv.writer(csvfile, delimiter='\t') + #csvwriter.writerow(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]) + dates = get_dates() + + window_opened = list() + time_spent = list() + for i in dates: + window_opened, time_spent = extract_data(i) + Total_screen_time = "00:00:00" + for x, y in final_report(window_opened, time_spent).items(): + Total_screen_time = to.time_addition(y, Total_screen_time) + + csvwriter.writerow([weekday_from_date(i), Total_screen_time]) + + for i in dates: + x, y = extract_data(str(i)) + window_opened += x + time_spent += y + for x, y in final_report(window_opened, time_spent).items(): + csvwriter.writerow([y, x]) + diff --git a/src/Watcher/colored_text.py b/src/Watcher/colored_text.py deleted file mode 100755 index bb7ec7c..0000000 --- a/src/Watcher/colored_text.py +++ /dev/null @@ -1,30 +0,0 @@ -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' - -#print(color.GREEN("hello")) diff --git a/src/Watcher/commands.py b/src/Watcher/commands.py index 6228133..dd1d2c4 100755 --- a/src/Watcher/commands.py +++ b/src/Watcher/commands.py @@ -2,14 +2,61 @@ import os import csv import datetime from watch_log import get_date -import report_creation as rc -from colored_text import Color +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 = rc.extract_data(date) - rc.prints_report(window_opened, time_spent) + 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] @@ -35,7 +82,7 @@ def week_summary(): for x, y in week_overview.items(): print(" " + f'{Color.YELLOW(x):>21}' + "\t\t " + Color.BLUE(to.format_time(y))) - #rc.prints_report(window_opened, time_spent, is_week) + #anls.prints_report(window_opened, time_spent, is_week) print(" ────────────────────────────────────────────────") print(Color.RED(f'{" App Usages":>29}')) print(" ────────────────────────────────────────────────") diff --git a/src/Watcher/report_creation.py b/src/Watcher/report_creation.py deleted file mode 100755 index 1e080db..0000000 --- a/src/Watcher/report_creation.py +++ /dev/null @@ -1,82 +0,0 @@ -import csv -import os -import time_operations as to -from watch_log import get_date -from colored_text import Color -import datetime - -def extract_data(date): - user = os.getlogin() - path = "/home/" + user +"/.cache/Watcher/raw_data/" - filename = path + date + ".csv" - - l = list() # l = list of (app_name, time spent on app on that session) - d = dict() - - if os.path.isfile(filename): - with open(filename, 'r') as file: - reader = csv.reader(file) - for row in reader: - for column in row: - l.append([column[18::],column[9:17]]) - d.update({column[18::]: "O"}) - else: - None - - d = list(d) # list of app opened on that day - return d, l - -# creating dictionary to store time spend on each applicaitons on that particular day -def final_report(window_opened, time_spent): - report = dict() - - for i in window_opened: # i is applications name - time = '00:00:00' - for j in time_spent: # j is list of applicaions_name and time_spent in particular session - if i == j[0]: - time = to.time_addition(j[1], time) - report.update({i:time}) - - #print(report) - if "User-logged-in" in report.keys(): - report.pop("User-logged-in") - # sort report dictonary in decreasing order of Usages - sorted_values = [] - for x,y in report.items(): - sorted_values.append(to.convert_into_sec(y)) - - sorted_values.sort(reverse=True) - sorted_report = dict() - - for i in sorted_values: - for x, y in report.items(): - if to.convert_into_sec(y) == i: - sorted_report.update({x:y}) - - return sorted_report - -# ░ ▒ █ ─── -#print("▒▒▒\t▒▒▒\n███") - -def prints_report(window_opened, time_spent): - Total_screen_time = "00:00:00" - for x,y in 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 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}') - - diff --git a/src/Watcher/time_operations.py b/src/Watcher/time_operations.py index 08a42ef..23326d9 100755 --- a/src/Watcher/time_operations.py +++ b/src/Watcher/time_operations.py @@ -1,4 +1,3 @@ - def time_difference(a,b): # b - a hr = int(b[0:2])-int(a[0:2]) mn = int(b[3:5])-int(a[3:5]) @@ -12,17 +11,17 @@ def time_difference(a,b): # b - a elif mn < 0 and sec >= 0: hr = hr - 1 mn = 60 + mn + if hr < 0: + hr = hr + 24 elif sec < 0 and mn > 0: sec = 60 + sec mn = mn - 1 if hr < 0: hr = hr + 24 - elif sec < 0 and mn == 0: hr = hr - 1 mn = 59 sec = 60 + sec - #elif int(mn) < 0: hr = str(hr).zfill(2) mn = str(mn).zfill(2) @@ -50,7 +49,6 @@ def time_addition(a,b): mn = str(mn).zfill(2) sec = str(sec).zfill(2) result = hr + ":" + mn + ":" + sec - return result def format_time(t): @@ -67,3 +65,4 @@ def convert_into_sec(t): sec = int(t[0:2])*3600 + int(t[3:5])*60 + int(t[6::]) return sec + diff --git a/src/Watcher/week_analysis.py b/src/Watcher/week_analysis.py deleted file mode 100755 index a82b5f3..0000000 --- a/src/Watcher/week_analysis.py +++ /dev/null @@ -1,46 +0,0 @@ -import os -import csv -import datetime -import report_creation as rc -import time_operations as to - -def get_dates(): - theday = datetime.date.today() - weekday = theday.isoweekday() - 1 - # The start of the week - start = theday - datetime.timedelta(days=weekday) - # build a simple range - dates = [start + datetime.timedelta(days=d) for d in range(weekday + 1)] - dates = [str(d) for d in dates] - - return dates - -def weekday_from_date(date): - day = os.popen('''date -d "'''+ date + '''" +%a''').read() - return day[0:-1] - -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, "w") as csvfile: - csvwriter = csv.writer(csvfile, delimiter='\t') - #csvwriter.writerow(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]) - dates = get_dates() - - window_opened = list() - time_spent = list() - for i in dates: - window_opened, time_spent = rc.extract_data(i) - Total_screen_time = "00:00:00" - for x, y in rc.final_report(window_opened, time_spent).items(): - Total_screen_time = to.time_addition(y, Total_screen_time) - - csvwriter.writerow([weekday_from_date(i), Total_screen_time]) - - for i in dates: - x, y = rc.extract_data(str(i)) - window_opened += x - time_spent += y - for x, y in rc.final_report(window_opened, time_spent).items(): - csvwriter.writerow([y, x]) - diff --git a/src/bin/watcher b/src/bin/watcher index d2392cd..4bea832 100644 --- a/src/bin/watcher +++ b/src/bin/watcher @@ -5,6 +5,7 @@ sys.path.insert(0, "/usr/share/Watcher/") import watch_log as x from commands import Color import commands as cmd +from analysis import weeklly_logs def help_option(): print(Color.BLUE("Watcher") + " - Minimal open source screen-time tracker\n") @@ -22,12 +23,12 @@ try: if arg == "-ds" or arg == "--day-summary": cmd.daily_summary() elif arg == "-ws" or arg == "--week-summary": - + weeklly_logs() cmd.week_summary() elif arg == "-h" or arg == "--help": help_option() elif arg == "--start": - print("Log creations started... \nif you wanna stop it, use keyboard-shortcut (Ctrl+Shift+C)") + print("Log creations started... \nif you wanna stop it, use keyboard-shortcut (Ctrl+Shift+C or Ctrl+C)") x.log_creation() elif arg == "--version": print("Version: 1.2") -- cgit v1.2.3 From ac79bbea7b113613bf160512064b8e2478181db9 Mon Sep 17 00:00:00 2001 From: Waishnav Date: Fri, 8 Jul 2022 23:22:47 +0530 Subject: updating installation guide in README.md --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1c3959f..414d7b4 100644 --- a/README.md +++ b/README.md @@ -20,15 +20,22 @@ Day Summary | Week Summary Funfact: You might be thinking how can someone has 14 hrs of screen time in a single day, Well ! short ans is AFK-feature is not implemented yet... Most of the time I left my laptop as it is so it also counts that AFK time as Screen-time ## Installation -* Note: Install [```xdotool```](https://github.com/jordansissel/xdotool) on your system ( its the only dependancy ) -* First, Clone this repository and cd into it- +* Note: Install [```xprintidle```](https://github.com/g0hl1n/xprintidle) on your system ( its the only dependancy ) +* First, Install the following dependancy +```xprintidle``` +```EWMH python module``` +```bash +$ sudo [package-manager] install xprintidle +$ pip install ewmh +``` +* Second, Clone this repository and cd into it- ```bash $ git clone https://github.com/Waishnav/Watcher $ cd ./Watcher/ ``` * Then run install script ```bash -$ ./install +$ chmod +x ./install && ./install ``` ## To-do -- cgit v1.2.3