From 9a9c5b176997c1aec0c1c05a9fbe3d3cc26eff99 Mon Sep 17 00:00:00 2001 From: Waishnav Date: Tue, 19 Jul 2022 22:25:50 +0530 Subject: added two commands -ds -y and -ws -pw --- src/Watcher/analysis.py | 14 +++++++------- src/Watcher/commands.py | 3 +++ src/bin/watcher | 7 +++++++ 3 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Watcher/analysis.py b/src/Watcher/analysis.py index d37010c..6e26d29 100755 --- a/src/Watcher/analysis.py +++ b/src/Watcher/analysis.py @@ -66,7 +66,7 @@ def get_sunday_of_week(week): 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()): +def week_dates(theday=datetime.date.today()): weekday = theday.isoweekday() - 1 # The start of the week (Monday) start = theday - datetime.timedelta(days=weekday) @@ -79,17 +79,17 @@ def weekday_from_date(date): day = os.popen('''date -d "'''+ date + '''" +%a''').read() return day[0:-1] -def weekly_logs(week = str(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/"+week+".csv" with open(filename, "w") as csvfile: csvwriter = csv.writer(csvfile, delimiter='\t') #csvwriter.writerow(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]) - if os.popen('''date +"w%v-%y"''').read()[0:-1] == week: - dates = get_date() + if os.popen('''date +"W%V-%Y"''').read()[0:-1] == week: + dates = week_dates() else: - dates = get_dates(get_sunday_of_week(week)) + dates = week_dates(get_sunday_of_week(week)) window_opened = list() time_spent = list() @@ -110,5 +110,5 @@ def weekly_logs(week = str(os.popen('''date +"w%v-%y"''').read()[0:-1])): #testing if __name__ == "__main__": - print(get_dates(get_sunday_of_week("W27-2022"))) - weekly_logs("W27-2022") + weekly_logs("W29-2022") + diff --git a/src/Watcher/commands.py b/src/Watcher/commands.py index 5e6826e..7d1fe97 100755 --- a/src/Watcher/commands.py +++ b/src/Watcher/commands.py @@ -90,6 +90,9 @@ def week_summary(week = os.popen('''date +"W%V-%Y"''').read()[:-1]): 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))) + elif week == os.popen("""date -d 'last week' '+W%W-%Y'""").read()[:-1]: + print(Color.PURPLE("\n Previous Week's \t\t ") + Color.BLUE(to.format_time(week_screen_time))) + print(Color.PURPLE(" 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 ")) diff --git a/src/bin/watcher b/src/bin/watcher index d944b37..f3228a8 100755 --- a/src/bin/watcher +++ b/src/bin/watcher @@ -54,12 +54,18 @@ elif len(arg) == 3: if arg[1] == "-ds" or arg[1] == "--day-summary": if len(arg[2]) == 10: cmd.daily_summary(str(arg[2])) + elif arg[2] == "--yestarday" or arg[2] == "-y": + cmd.daily_summary(os.popen("""date -d "1 day ago" '+%Y-%m-%d'""").read()[:-1]) 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])) + elif arg[2] == "--previous_week" or arg[2] == "-pw": + prev_week=os.popen("""date -d 'last week' '+W%W-%Y'""").read()[:-1] + weekly_logs(prev_week) + cmd.week_summary(prev_week) else: wrong_option() else: @@ -71,3 +77,4 @@ else: #parser.add_argument() #args = parser.parse_args() #print(args) + -- cgit v1.2.3