aboutsummaryrefslogtreecommitdiff
path: root/src/Watcher/watch_log.py
diff options
context:
space:
mode:
authorLibravatar Waishnav <waishnavdeore@gmail.com>2022-07-08 20:23:17 +0530
committerLibravatar Waishnav <waishnavdeore@gmail.com>2022-07-08 20:23:17 +0530
commit471d0b43e3fa2f5f077ce9ad4824992058d26e0e (patch)
treed262855355d683074c21bb39f196e98e4d26cc94 /src/Watcher/watch_log.py
parentaf16350b30a9f02974ddc880ee51bf475cb150f8 (diff)
downloadshopno-os-log-sync-471d0b43e3fa2f5f077ce9ad4824992058d26e0e.tar.gz
shopno-os-log-sync-471d0b43e3fa2f5f077ce9ad4824992058d26e0e.zip
updating log file algorithm | added AFK feature | changing dependency xdotool to ewmh
Diffstat (limited to 'src/Watcher/watch_log.py')
-rwxr-xr-xsrc/Watcher/watch_log.py54
1 files changed, 28 insertions, 26 deletions
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)