diff options
-rwxr-xr-x | src/Watcher/get_windows.py | 14 | ||||
-rwxr-xr-x | src/Watcher/watch_log.py | 12 | ||||
-rwxr-xr-x | src/bin/watcher | 2 |
3 files changed, 21 insertions, 7 deletions
diff --git a/src/Watcher/get_windows.py b/src/Watcher/get_windows.py index 8f30932..19e2a3a 100755 --- a/src/Watcher/get_windows.py +++ b/src/Watcher/get_windows.py @@ -4,12 +4,13 @@ from afk import get_afk_status # get title name of app that user working on def active_window_title(): - active_window_title = os.popen("""xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) WM_NAME | sed -nr 's/.*= "(.*)"$/\1/p'""").read()[:-1] + active_window_title = os.popen('''xprop -id $(xdotool getwindowfocus) WM_NAME''').read()[19:-2] + a = active_window_title.find('"') + active_window_title = active_window_title[a+1:] if "XGetWindowProperty[_NET_ACTIVE_WINDOW] failed" in active_window_title: active_window_title = "" if "\n" in active_window_title: active_window_title = "Unknown" - active_window_title = active_window_title.capitalize() return active_window_title # get classname of app that user working on @@ -30,9 +31,9 @@ def active_window(): 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: try: - if "Nvim" in aw_title: + if "nvim" in aw_title: active_window = "NeoVim" - elif "Vim" in aw_title: + elif "vim" in aw_title: active_window = "Vim" except TypeError: None @@ -57,3 +58,8 @@ def is_window_changed(a, afk, timeout): ### 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()) diff --git a/src/Watcher/watch_log.py b/src/Watcher/watch_log.py index 250670d..1316cd1 100755 --- a/src/Watcher/watch_log.py +++ b/src/Watcher/watch_log.py @@ -47,15 +47,23 @@ def log_creation(): if (y.returned_from_afk(afk, afkTimeout)): previous_window = "AFK" + opened_at = os.popen(" tail -n1 "+ filename).read().split("\t")[0] afk = False if (x.is_window_changed(previous_window, afk, afkTimeout) and not afk): if(y.is_afk(afkTimeout)): afk = True - closed_at = get_time() # for next_window its the opening time + # minimizing error + closed_at = time_difference("00:02:58", get_time()) + else: + closed_at = get_time() # for next_window its the opening time + date = get_date() filename = "/home/"+os.getlogin()+"/.cache/Watcher/raw_data/"+date+".csv" append_line_in_csv(date, opened_at, closed_at, previous_window) if __name__ == "__main__": - log_creation() + #log_creation() + filename = "/home/"+os.getlogin()+"/.cache/Watcher/raw_data/"+get_date()+".csv" + opened_at = os.popen(" tail -n1 "+ filename).read().split("\t")[0] + print(opened_at) diff --git a/src/bin/watcher b/src/bin/watcher index f3228a8..2644fd1 100755 --- a/src/bin/watcher +++ b/src/bin/watcher @@ -46,7 +46,7 @@ if len(arg) == 2: print("Log creations started... \nif you wanna stop it, use keyboard-shortcut (Ctrl+Shift+C or Ctrl+C)") x.log_creation() elif arg[1] == "--version" or arg[1] == "-v": - print("Version: 1.3") + print("Version: 1.3.1") else: wrong_option() |