diff options
author | 2022-03-18 23:28:08 +0530 | |
---|---|---|
committer | 2022-03-18 23:28:08 +0530 | |
commit | cc9599c1a3de1f90ffc22c7b4a19bf2cad85e9d8 (patch) | |
tree | 51f2f60b31fa6fc6f57340496b52beedb0cf684e | |
parent | 4c53701e1505273ff96ac4158aaf5df339c20b16 (diff) | |
download | shopno-os-log-sync-cc9599c1a3de1f90ffc22c7b4a19bf2cad85e9d8.tar.gz shopno-os-log-sync-cc9599c1a3de1f90ffc22c7b4a19bf2cad85e9d8.zip |
changing approach to problem occured at 24:00 clock | added prompt in install script
-rwxr-xr-x | install | 21 | ||||
-rwxr-xr-x | src/Watcher/watch_log.py | 22 |
2 files changed, 27 insertions, 16 deletions
@@ -1,23 +1,28 @@ #!/bin/bash -echo "[*] Thanks for landing here." +echo "[✔] First of all Thanks for dropping by!." +sleep 1s +echo "[✔] And...FYI Watcher uses very less resources like almost 10 MBs." sleep 2s -echo "[*] First off all Watcher uses very less resources like almost 10 MBs." -sleep 3s -echo "[*] Also some of the features are in development AFK is one of them" +echo "[✔] Also some of the features are in development AFK is one of them" sleep 2s -echo "[*] So let's start installtion process... " +echo "[✔] So let's start installtion process... " sudo cp -r ./src/Watcher /usr/share/ +echo "[✔] Copying Watcher to /usr/share/" sudo cp -r ./src/bin/watcher /usr/local/bin/ +echo "[✔] Copying watcher executable to /usr/local/bin/" sudo chmod +x /usr/local/bin/watcher +echo "[✔] Making it executable by giving giving it permission" # making directory for log-files (where all you daily logs are stored) mkdir -p ~/.cache/Watcher/ +echo "[✔] To store raw_data making directory as ~/.cache/Watcher" mkdir -p ~/.cache/Watcher/raw_data/ mkdir -p ~/.cache/Watcher/Analysis/ # resolving confilict with previous version of watcher +echo "[✔] Checking whether you had installed previous version so removing conflicts if yes" if [ -f "$HOME/.config/systemd/user/watcher.service" ]; then systemctl --user disable --now watcher.service rm -rf $HOME/.config/systemd/user/watcher.service @@ -33,6 +38,7 @@ else count2=0 fi +echo "[✔] Making sure that it will run at starting of each xsession afterward" if [[ $count1 > 0 ]];then if [[ $count2 = 0 ]];then echo "killall watcher" >> $HOME/.xprofile @@ -43,6 +49,5 @@ else echo "[ -f ~/.xprofile ] && . ~/.xprofile" >> $HOME/.xinitrc fi -echo "Now you can use Watcher after restart. and see you around if anything goes wrong do PR or smth else" - -[ -f ~/.xprofile ] && . ~/.xprofile +echo "Now you can use Watcher after restart. and see you around if anything goes wrong do PR or open issue" +echo '''If you wanna just give a try (without restart), You can start taking logs (run watch_log.py) by "watcher --start"''' diff --git a/src/Watcher/watch_log.py b/src/Watcher/watch_log.py index 46abc15..704ee3f 100755 --- a/src/Watcher/watch_log.py +++ b/src/Watcher/watch_log.py @@ -41,21 +41,27 @@ def log_creation(): with open(filename, 'a') as csvfile: csvwriter = csv.writer(csvfile, delimiter='\t') csvwriter.writerow([get_time(), "00:00:00", ""]) - append_line_in_csv(get_date(), get_time(), "User-logged-in") - while True: - filename = "/home/"+os.getlogin()+"/.cache/Watcher/raw_data/"+get_date()+".csv" - if not(os.path.isfile(filename)): - with open(filename, 'a') as csvfile: - csvwriter = csv.writer(csvfile, delimiter='\t') - csvwriter.writerow([get_time(), "00:00:00", ""]) + while True: 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 date = get_date() - append_line_in_csv(date, closed_at, previous_window) + filename = "/home/"+os.getlogin()+"/.cache/Watcher/raw_data/"+date+".csv" + if not(os.path.isfile(filename)): + with open(filename, 'a') as csvfile: + csvwriter = csv.writer(csvfile, delimiter='\t') + prev_date = os.popen("""date -d "yesterday" '+%Y-%m-%d'""") + prev_file = "/home/"+os.getlogin()+"/.cache/Watcher/raw_data/"+prev_date+".csv" + with open(prev_file, 'r') as file: + last_app_time = file.readlines()[-1][0:8] + csvwriter.writerow([get_time(), time_difference(last_app_time, closed_at), previous_window]) + + else: + # appends line when app gets closed + append_line_in_csv(date, closed_at, previous_window) if afk: afk_closed_time = get_time() |