aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xinstall2
-rwxr-xr-xsrc/Watcher/analysis.py30
-rwxr-xr-xsrc/Watcher/commands.py45
-rwxr-xr-x[-rw-r--r--]src/bin/watcher65
-rwxr-xr-xupdate7
5 files changed, 106 insertions, 43 deletions
diff --git a/install b/install
index fbeb7f0..dedccfa 100755
--- a/install
+++ b/install
@@ -3,7 +3,7 @@
echo "[✔] First of all Thanks for dropping by!."
sleep 1s
echo "[✔] And...FYI Watcher uses very less resources like almost 10 MBs."
-sleep 2s
+sleep 1s
echo "[✔] Also some of the features are in development AFK is one of them"
sleep 2s
echo "[✔] So let's start installation process... "
diff --git a/src/Watcher/analysis.py b/src/Watcher/analysis.py
index 87acda3..d37010c 100755
--- a/src/Watcher/analysis.py
+++ b/src/Watcher/analysis.py
@@ -58,30 +58,38 @@ def final_report(window_opened, time_spent):
return sorted_report
-# getting dates of the week for week summary
-def get_dates():
- theday = datetime.date.today()
+def get_sunday_of_week(week):
+ year = int(week[4:])
+ week = int(week[1:3])
+ first = datetime.date(year, 1, 1)
+ base = 1 if first.isocalendar()[1] == 1 else 8
+ return first + datetime.timedelta(days=base - first.isocalendar()[2] + 7 * (week - 1)) + datetime.timedelta(days=6.9)
+
+# getting dates of particular week for week summary
+def get_dates(theday=datetime.date.today()):
weekday = theday.isoweekday() - 1
- # The start of the week
+ # The start of the week (Monday)
start = theday - datetime.timedelta(days=weekday)
# build a simple range
dates = [start + datetime.timedelta(days=d) for d in range(weekday + 1)]
dates = [str(d) for d in dates]
-
return dates
def weekday_from_date(date):
day = os.popen('''date -d "'''+ date + '''" +%a''').read()
return day[0:-1]
-def weeklly_logs():
- W_Y = os.popen('''date +"W%V-%Y"''').read()[0:-1]
+def weekly_logs(week = str(os.popen('''date +"w%v-%y"''').read()[0:-1])):
user = os.getlogin()
- filename = "/home/"+user+"/.cache/Watcher/Analysis/"+W_Y+".csv"
+ filename = "/home/"+user+"/.cache/Watcher/Analysis/"+week+".csv"
with open(filename, "w") as csvfile:
csvwriter = csv.writer(csvfile, delimiter='\t')
#csvwriter.writerow(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"])
- dates = get_dates()
+
+ if os.popen('''date +"w%v-%y"''').read()[0:-1] == week:
+ dates = get_date()
+ else:
+ dates = get_dates(get_sunday_of_week(week))
window_opened = list()
time_spent = list()
@@ -100,3 +108,7 @@ def weeklly_logs():
for x, y in final_report(window_opened, time_spent).items():
csvwriter.writerow([y, x])
+#testing
+if __name__ == "__main__":
+ print(get_dates(get_sunday_of_week("W27-2022")))
+ weekly_logs("W27-2022")
diff --git a/src/Watcher/commands.py b/src/Watcher/commands.py
index dd1d2c4..5e6826e 100755
--- a/src/Watcher/commands.py
+++ b/src/Watcher/commands.py
@@ -34,20 +34,33 @@ class Color:
def UNDERLINE(text):
return '\033[4m' + text + '\033[0m'
-
-def daily_summary():
- date = get_date()
+def daily_summary(date = get_date()):
window_opened, time_spent = anls.extract_data(date)
Total_screen_time = "00:00:00"
for x,y in anls.final_report(window_opened, time_spent).items():
Total_screen_time = to.time_addition(y, Total_screen_time)
- if len(to.format_time(Total_screen_time)) == 3:
- print(Color.YELLOW("\n Today's Screen-Time\t\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>16}'))
- elif len(to.format_time(Total_screen_time)) == 7:
- print(Color.YELLOW("\n Today's Screen-Time\t\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>11}'))
- elif len(to.format_time(Total_screen_time)) == 11:
+ if date == get_date():
+ if len(to.format_time(Total_screen_time)) == 3:
+ print(Color.YELLOW("\n Today's Screen-Time\t\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>16}'))
+ elif len(to.format_time(Total_screen_time)) == 7:
+ print(Color.YELLOW("\n Today's Screen-Time\t\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>11}'))
+ elif len(to.format_time(Total_screen_time)) == 11:
print(Color.YELLOW("\n Today's Screen-Time\t\t ") + Color.BLUE(to.format_time(Total_screen_time)))
+ elif date == os.popen("""date -d "1 day ago" '+%Y-%m-%d'""").read()[:-1]:
+ if len(to.format_time(Total_screen_time)) == 3:
+ print(Color.YELLOW("\n Yestarday's Screen-Time\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>16}'))
+ elif len(to.format_time(Total_screen_time)) == 7:
+ print(Color.YELLOW("\n Yestarday's Screen-Time\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>11}'))
+ elif len(to.format_time(Total_screen_time)) == 11:
+ print(Color.YELLOW("\n Yestarday's Screen-Time\t ") + Color.BLUE(to.format_time(Total_screen_time)))
+ else:
+ if len(to.format_time(Total_screen_time)) == 3:
+ print(Color.YELLOW("\n "+date+"'s Screen-Time\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>6}'))
+ elif len(to.format_time(Total_screen_time)) == 7:
+ print(Color.YELLOW("\n "+ date+ "'s Screen-Time\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>1}'))
+ elif len(to.format_time(Total_screen_time)) == 11:
+ print(Color.YELLOW("\n "+date+"'s Screen-Time\t ") + Color.BLUE(to.format_time(Total_screen_time)))
print(" ────────────────────────────────────────────────")
print(Color.RED(f'{" App Usages":>29}'))
@@ -58,10 +71,9 @@ def daily_summary():
x = "Home-Screen"
print(" " + Color.GREEN(f'{x:<22}') + '\t ',f'{to.format_time(y):>12}')
-def week_summary():
- W_Y = os.popen('''date +"W%V-%Y"''').read()[0:-1]
+def week_summary(week = os.popen('''date +"W%V-%Y"''').read()[:-1]):
user = os.getlogin()
- filename = "/home/"+user+"/.cache/Watcher/Analysis/"+W_Y+".csv"
+ filename = "/home/"+user+"/.cache/Watcher/Analysis/"+week+".csv"
with open(filename, 'r') as file:
csvreader = csv.reader(file, delimiter='\t')
week_overview = dict()
@@ -76,7 +88,12 @@ def week_summary():
for x, y in week_overview.items():
week_screen_time = to.time_addition(y, week_screen_time)
- print(Color.PURPLE("\n Week's screen-time\t\t ") + Color.BLUE(to.format_time(week_screen_time)))
+ if week == os.popen('''date +"W%V-%Y"''').read()[:-1]:
+ print(Color.PURPLE("\n Week's screen-time\t\t ") + Color.BLUE(to.format_time(week_screen_time)))
+ else:
+ print(Color.PURPLE("\n "+week[1:3]+ "th week of\t ") + Color.BLUE(to.format_time(week_screen_time)))
+ print(Color.PURPLE(" "+week[4:] +" screen-time\t "))
+
print(" ────────────────────────────────────────────────")
for x, y in week_overview.items():
@@ -91,5 +108,7 @@ def week_summary():
x = "Home-Screen"
print(" " + Color.GREEN(f'{x:<22}') + '\t ',f'{to.format_time(y):>12}')
+#testing
if __name__ == "__main__":
- week_summary()
+ week_summary("W27-2022")
+ #daily_summary("2022-07-18")
diff --git a/src/bin/watcher b/src/bin/watcher
index f9d291c..d944b37 100644..100755
--- a/src/bin/watcher
+++ b/src/bin/watcher
@@ -5,43 +5,68 @@ sys.path.insert(0, "/usr/share/Watcher/")
import watch_log as x
from commands import Color
import commands as cmd
-from analysis import weeklly_logs
+from analysis import weekly_logs
def help_option():
print(Color.BLUE("Watcher") + " - Minimal open source screen-time tracker\n")
print(Color.YELLOW("USAGE:")+"\n\t watcher [OPTION]\n")
print(Color.YELLOW("OPTIONS"))
- print("\t-ds, --day-summary Displays where you have spend your time of that day")
- print("\t-ws, --week-summary Displays screen-time of each day of week")
+ print("\t-ds, --day-summary Shows today's screen-time and app-usage")
+ print("\t-ds [date] Shows that day's screen-time and app-usage\n\t\t\t\t\t (if date is not given then date=today's date)")
+ print("\t-ws, --week-summary Shows screen-time of each day of that running week")
+ print("\t-ws [week] Shows screen-time of each day of that week given by you")
print("\t-s, --start It starts taking logs afterwards in following directory ~/.cache/Watcher/raw_data/")
- print("\nFor more information see github repo: https://github.com/Waishnav/Watcher and Don't forget to star the repo")
+ print(Color.YELLOW("\nEXAMPLE COMMANDS"))
+ print("\twatcher -ds 2022-01-31")
+ print("\twatcher -ws W01-2022")
+ print("\nFor more information see github repo: "+ Color.BLUE("https://github.com/Waishnav/Watcher") +" and Don't forget to star the repo")
+
+def wrong_option():
+ print(Color.RED("Wrong")+" [OPTION] choosen. Have a look at the Options!!\n")
+ print(Color.YELLOW("OPTIONS"))
+ print("\t-ds or --day-summary [date] Displays where you have spend your time of that day")
+ print("\t-ws or --week-summary [week] Displays screen-time of each day of week")
+ print(Color.YELLOW("\nEXAMPLE COMMANDS"))
+ print("\twatcher -ds 2022-01-31")
+ print("\twatcher -ws W01-2022")
+ print("\nFor more information see github repo: "+ Color.BLUE("https://github.com/Waishnav/Watcher") +" and Don't forget to star the repo")
#print("▒▒▒\t▒▒▒\n███")
-try:
- arg = sys.argv[1]
- if arg == "-ds" or arg == "--day-summary":
+arg = sys.argv
+if len(arg) == 2:
+ if arg[1] == "-ds" or arg[1] == "--day-summary":
cmd.daily_summary()
- elif arg == "-ws" or arg == "--week-summary":
- weeklly_logs()
+ elif arg[1] == "-ws" or arg[1] == "--week-summary":
+ weekly_logs()
cmd.week_summary()
- elif arg == "-h" or arg == "--help":
+ elif arg[1] == "-h" or arg[1] == "--help":
help_option()
- elif arg == "--start" or arg == "-s":
+ elif arg[1] == "--start" or arg[1] == "-s":
print("Log creations started... \nif you wanna stop it, use keyboard-shortcut (Ctrl+Shift+C or Ctrl+C)")
x.log_creation()
- elif arg == "--version":
- print("Version: 1.2")
+ elif arg[1] == "--version" or arg[1] == "-v":
+ print("Version: 1.3")
else:
- print(Color.RED("Wrong")+" [OPTION] choosen. Have a look at the Options!!\n")
- print(Color.YELLOW("OPTIONS"))
- print("\t-ds, --day-summary Displays where you have spend your time of that day")
- print("\t-ws, --week-summary Displays screen-time of each day of week")
- print("\nFor more information see github repo: https://github.com/Waishnav/Watcher and Don't forget to star the repo")
+ wrong_option()
-except IndexError:
- help_option()
+elif len(arg) == 3:
+ if arg[1] == "-ds" or arg[1] == "--day-summary":
+ if len(arg[2]) == 10:
+ cmd.daily_summary(str(arg[2]))
+ else:
+ wrong_option()
+ elif arg[1] == "-ws" or arg[1] == "--week-summary":
+ if len(arg[2]) == 8:
+ weekly_logs(str(arg[2]))
+ cmd.week_summary(str(arg[2]))
+ else:
+ wrong_option()
+ else:
+ wrong_option()
+else:
+ wrong_option()
#parser = argparse.ArgumentParser(description="Minimal open source screen-time calulator for digitally wellbeing")
#parser.add_argument()
#args = parser.parse_args()
diff --git a/update b/update
new file mode 100755
index 0000000..d932630
--- /dev/null
+++ b/update
@@ -0,0 +1,7 @@
+#!/bin/bash
+sudo rm -rf /usr/share/Watcher/*
+sudo cp -r ./src/Watcher/* /usr/share/Watcher/
+
+sudo cp -r ./src/bin/watcher /usr/local/bin/
+sudo chmod +x /usr/local/bin/watcher
+echo "[✔] Updating Finished."