def dispatch_visit(self, node): #print(node) if node.__class__ == docutils.nodes.section: title = node.children[0].rawsource m = re.match(r"(?P<y>\d{4})-(?P<m>\d{2})-(?P<d>\d{2}) \((Mon|Tue|Wed|Thu|Fri|Sat|Sun)\)", title) if m is None: #print("Skipping %s" % title) return def toi(x): return int(m.group(x)) self.date = datetime.datetime(year=toi("y"), month=toi("m"), day=toi("d")) self.date = self.date.replace(second=1) if node.__class__ == docutils.nodes.admonition: title = node.children[0].rawsource if not title.startswith("Hours"): return assert self.date is not None, "Sonna bakana!" print("- %s" % self.date.strftime("%Y-%m-%d")) assert node.children[1].__class__ == docutils.nodes.bullet_list, node.children[1] entries = node.children[1].children dayjob = datetime.timedelta() print(" - Entries:") for entry in entries: assert len(entry.children) == 1, entry assert entry.children[0].__class__ == docutils.nodes.paragraph pr = entry.children[0].rawsource p = pr.splitlines()[0] pr = pr.replace("\n", " ") re_a = r"^From :time:`(?P<from>\d{2}:\d{2}:\d{2})` to :time:`(?P<to>\d{2}:\d{2}:\d{2})`,?.*$" m = re.match(re_a, p) if m is not None: tsf = m.group("from") tst = m.group("to") f = datetime.datetime.strptime(tsf, "%H:%M:%S") f = f.replace(year=self.date.year, month=self.date.month, day=self.date.day) t = datetime.datetime.strptime(tst, "%H:%M:%S") t = t.replace(year=self.date.year, month=self.date.month, day=self.date.day) if t < f: t += datetime.timedelta(hours=24) dt = t-f dayjob += dt print(" - %s: %s" % (dt, pr)) if f < self.min_date: f = self.min_date if t > self.max_date: t = self.max_date if t > f: print(" Considered %s" % (t-f)) self.entries.append((self.date, t-f)) continue re_a = r"^From :time:`(?P<from>\d{2}:\d{2})` to :time:`(?P<to>\d{2}:\d{2})`,?.*$" m = re.match(re_a, p) if m is not None: tsf = m.group("from") tst = m.group("to") f = datetime.datetime.strptime(tsf, "%H:%M") f = f.replace(year=self.date.year, month=self.date.month, day=self.date.day) t = datetime.datetime.strptime(tst, "%H:%M") t = t.replace(year=self.date.year, month=self.date.month, day=self.date.day) if t < f: t += datetime.timedelta(hours=24) dt = t-f dayjob += dt print(" - %s: %s" % (dt, pr)) if f < self.min_date: f = self.min_date if t > self.max_date: t = self.max_date if t > f: print(" Considered %s" % (t-f)) self.entries.append((self.date, t-f)) continue re_a = r"^Estimated :time:`((?P<h>\d+)h)?((?P<m>\d+)m?)?`,?\s*.*$" m = re.match(re_a, p) if m is not None: d = dict(m.groupdict()) h = int(d.get('h', 0) or 0) m = float(d.get("m", 0) or 0) dt = datetime.timedelta(hours=h, minutes=m) print(" - %s: %s" % (dt, pr)) dayjob += dt if self.date >= self.min_date and self.date <= self.max_date: self.entries.append((self.date, dt)) continue assert False, p print(" - Day total: %s" % datetimeparse.timedelta_str(dayjob))
} d = dict() for k, xform in type_xform.items(): v = getattr(args, k) if v is not None: d[k] = xform(v) s = f(**d) xm_rst_log.log_echo(s) elif args.command == "timesheet": entries = [] for date_range in args.range: entries += xm_rst_to_timesheet_estimation.process(args.filename, date_range) total = datetime.timedelta() print("Entries:") for date, date_work in entries: print("- %s: %s" % (date.strftime("%Y-%m-%d"), datetimeparse.timedelta_str(date_work))) total += date_work print("Total %.2f h" % (total.total_seconds() / (60.0*60))) elif args.command == "ts": xm_rst_log.log_echo(xm_rst_log.log_ts()) elif args.command == "clipboard": if args.cb_command == "stats": import subprocess cmd = "xclip -selection primary -out".split() lines = subprocess.check_output(cmd).decode().splitlines() lines = [x for x in lines if x != ""] words = 0 for line in lines: words += len(line.split()) print("Lines: %d" % len(lines)) print("Words: %d" % words)