def clocked_in_info(self): """Return (project, date) if a user is configured and the last action was a clockin, otherwise (None, None) """ f = file_for_current_user() if f: last_line = f.readlines()[-1] if "clockin" in last_line: return parse_clockin(last_line) else: return None, None else: return None, None
def execute(self, args): proj = " ".join(args.project) if proj: projects = [proj] + args.more_projects else: projects = args.more_projects if not projects: projects = None from_time, to_time = parse_date_range_args(args.tfrom, args.tto) total_time = datetime.timedelta() project_sums = defaultdict(lambda: datetime.timedelta()) for file_path in all_files(): with open(file_path, "r") as f: lines = f.readlines() i = 0 while i < len(lines): line = lines[i].strip() this_proj, clockin_time = parse_clockin(line) if i == len(lines) - 1: clockout_time = now else: clockout_time = parse_clockout(lines[i + 1]) if projects is None or this_proj in projects: if from_time is None or clockin_time >= from_time: if to_time is None or clockout_time <= to_time: dt = clockout_time - clockin_time project_sums[this_proj] += dt total_time += dt i += 2 for name in sorted(project_sums.keys()): log.info("%s: %s" % (name, self._format_timedelta(project_sums[name]))) if project_sums: log.info("") log.info("Total: %s" % self._format_timedelta(total_time)) if from_time or to_time != now: log.info("Periods are only counted if their start *and* end times are within the given range.")