aboutsummaryrefslogtreecommitdiff
path: root/src/Watcher/log_files.py
diff options
context:
space:
mode:
authorLibravatar Waishnav <[email protected]>2022-03-09 00:01:36 +0530
committerLibravatar Waishnav <[email protected]>2022-03-09 00:01:36 +0530
commit5e552e7b007f8b13bd3edb221cb162414bac6f03 (patch)
tree4f23442b6d594602b4bdff610255e75357a7a90d /src/Watcher/log_files.py
parent994d2a2a25a32a003660c61cb9600f22475c76a8 (diff)
downloadshopno-os-log-sync-5e552e7b007f8b13bd3edb221cb162414bac6f03.tar.gz
shopno-os-log-sync-5e552e7b007f8b13bd3edb221cb162414bac6f03.zip
initializing project with bare minimal features
Diffstat (limited to '')
-rwxr-xr-xsrc/Watcher/log_files.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Watcher/log_files.py b/src/Watcher/log_files.py
new file mode 100755
index 0000000..1d73b95
--- /dev/null
+++ b/src/Watcher/log_files.py
@@ -0,0 +1,58 @@
+import os
+import csv
+import time
+import get_windows as x
+
+# get current time whenever the function is called
+def get_time():
+ t = os.popen('''date +"%T"''').read()
+ return t[0:-1]
+
+# get date of today
+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):
+ user = os.getlogin()
+ filename = "/home/"+user+"/.cache/Watcher/raw_data/"+date+".csv"
+ Data = [opened_time, 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
+
+# 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
+
+ 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()
+ date = get_date()
+ append_line_in_csv(date, opened_at, next_window)
+
+ if afk:
+ opened_at = get_time()
+ append_line_in_csv(date, opened_at, "AFK")
+
+
+if __name__ == "__main__":
+ log_creation()