From 2a606b947dc318a783cfd202a446c03586a95cf4 Mon Sep 17 00:00:00 2001 From: Waishnav Date: Sat, 17 Sep 2022 05:09:46 +0530 Subject: updated algorithm | update csv at every second --- src/Watcher/get_windows.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'src/Watcher/get_windows.py') diff --git a/src/Watcher/get_windows.py b/src/Watcher/get_windows.py index 0769eb9..008defa 100755 --- a/src/Watcher/get_windows.py +++ b/src/Watcher/get_windows.py @@ -42,18 +42,10 @@ def active_window(): return active_window # returns true if user has move to next app which is not the same as previous -def is_window_changed(a, afk, timeout): - result = False - while not(result): - time.sleep(0.5) - b = active_window() - if a != b : - result = True - elif get_afk_status(afk, timeout): - result = True - else: - result = False - return result +def previous_window(array_of_window, active_window): + array_of_window.remove(active_window) + array_of_window.append(active_window) + return l[-2] ### what to do after window get change I've to append one line in csv data file in following format -- cgit v1.2.3 From 9fd05fa5f70164aaa7df70bdf4b6b467f7108f22 Mon Sep 17 00:00:00 2001 From: Waishnav Date: Sat, 17 Sep 2022 06:37:49 +0530 Subject: removed outdated comment --- src/Watcher/get_windows.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/Watcher/get_windows.py') diff --git a/src/Watcher/get_windows.py b/src/Watcher/get_windows.py index 008defa..c22d909 100755 --- a/src/Watcher/get_windows.py +++ b/src/Watcher/get_windows.py @@ -1,7 +1,13 @@ import os import time +import platform from afk import get_afk_status +if platform.system() == 'Windows': + from win32gui import GetWindowText, GetForegroundWindow +elif platform.system() == 'Darwin': + import subprocess + # get title name of app that user working on def active_window_title(): active_window_title = os.popen('''xprop -id $(xdotool getwindowfocus) WM_NAME''').read()[19:-2] @@ -47,13 +53,3 @@ def previous_window(array_of_window, active_window): array_of_window.append(active_window) return l[-2] - -### 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 - -### and whenever the user puts particular command it will make report till the time for that day and shows that report in terminal -if __name__ == "__main__": - while True: - time.sleep(1) - print(active_window_title()) - print(os.popen('''xdotool getwindowfocus getwindowname''').read()) -- cgit v1.2.3 From 4c214e401abc4d7d4c9a7182348b6bebf78de34a Mon Sep 17 00:00:00 2001 From: Waishnav Date: Mon, 14 Nov 2022 11:03:06 +0530 Subject: changed some variable names --- src/Watcher/get_windows.py | 12 +++--------- src/Watcher/watch_log.py | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'src/Watcher/get_windows.py') diff --git a/src/Watcher/get_windows.py b/src/Watcher/get_windows.py index c22d909..a0be469 100755 --- a/src/Watcher/get_windows.py +++ b/src/Watcher/get_windows.py @@ -1,12 +1,4 @@ import os -import time -import platform -from afk import get_afk_status - -if platform.system() == 'Windows': - from win32gui import GetWindowText, GetForegroundWindow -elif platform.system() == 'Darwin': - import subprocess # get title name of app that user working on def active_window_title(): @@ -51,5 +43,7 @@ def active_window(): def previous_window(array_of_window, active_window): array_of_window.remove(active_window) array_of_window.append(active_window) - return l[-2] + return array_of_window[-2] +if __name__ == "__main__": + print(active_window()) diff --git a/src/Watcher/watch_log.py b/src/Watcher/watch_log.py index 0d2095a..6a44ca5 100755 --- a/src/Watcher/watch_log.py +++ b/src/Watcher/watch_log.py @@ -16,7 +16,6 @@ def get_date(): return d[0:-1] def update_csv(date, Data): - user = os.getlogin() filename = "/home/"+os.getlogin()+"/.cache/Watcher/daily_data/"+date+".csv" overwrite_Data = [] with open(filename, 'w') as csvfile: @@ -57,6 +56,7 @@ def log_creation(): date = get_date() filename = "/home/"+os.getlogin()+"/.cache/Watcher/daily_data/"+date+".csv" afk = y.is_afk(afkTimeout) + print(data) if not(afk): active_window = x.active_window() -- cgit v1.2.3