aboutsummaryrefslogtreecommitdiff
path: root/src/Watcher/log_files.py
diff options
context:
space:
mode:
authorLibravatar Waishnav <waishnavdeore@gmail.com>2022-03-10 22:49:35 +0530
committerLibravatar Waishnav <waishnavdeore@gmail.com>2022-03-10 22:49:35 +0530
commit76405c161762626fe8aece13c2758f68c837ceb9 (patch)
treefa9b0086b8122b352899921bcff21e74e8b912cb /src/Watcher/log_files.py
parent5e552e7b007f8b13bd3edb221cb162414bac6f03 (diff)
downloadshopno-os-log-sync-76405c161762626fe8aece13c2758f68c837ceb9.tar.gz
shopno-os-log-sync-76405c161762626fe8aece13c2758f68c837ceb9.zip
log_files(implementing new approach) | so some changes in report_creation
Diffstat (limited to 'src/Watcher/log_files.py')
-rwxr-xr-xsrc/Watcher/log_files.py30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/Watcher/log_files.py b/src/Watcher/log_files.py
index 1d73b95..9dfc713 100755
--- a/src/Watcher/log_files.py
+++ b/src/Watcher/log_files.py
@@ -2,6 +2,7 @@ import os
import csv
import time
import get_windows as x
+from time_operations import time_difference
# get current time whenever the function is called
def get_time():
@@ -13,24 +14,19 @@ def get_date():
d = os.popen('''date +"%Y-%m-%d"''').read()
return d[0:-1]
-def append_line_in_csv(date, opened_time, window_name):
+def append_line_in_csv(date, closed_time, window_name):
user = os.getlogin()
filename = "/home/"+user+"/.cache/Watcher/raw_data/"+date+".csv"
- Data = [opened_time, window_name]
+ with open(filename, 'r') as file:
+ last_app_time = file.readlines()[-1][0:8]
+
+ time_spent = time_difference(last_app_time, closed_time)
+
+ Data = [closed_time, time_spent, window_name]
with open(filename, 'a') as csvfile:
csvwriter = csv.writer(csvfile, delimiter='\t')
csvwriter.writerow(Data)
-def is_date_changed(a):
- result = False
- while not(result):
- time.sleep(1)
- b = get_date()
- if a != b :
- result = True
- else:
- result = False
- return result
# 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
@@ -40,18 +36,18 @@ def is_date_changed(a):
afk = False
def log_creation():
global afk
-
+ append_line_in_csv(get_date(), get_time(), "User-loged-in")
while True:
previous_window = x.active_window()
if x.is_window_changed(previous_window) and not(afk):
next_window = x.active_window()
- opened_at = get_time()
+ closed_at = get_time() # for next_window its the opening time
date = get_date()
- append_line_in_csv(date, opened_at, next_window)
+ append_line_in_csv(date, closed_at, previous_window)
if afk:
- opened_at = get_time()
- append_line_in_csv(date, opened_at, "AFK")
+ afk_closed_time = get_time()
+ append_line_in_csv(date, afk_closed_time, "AFK")
if __name__ == "__main__":