From 1d75b5a3fa412c4094f6a30e49d9cfcb3c91b255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andy=20Teijelo=20P=C3=A9rez?= Date: Thu, 20 Apr 2017 07:34:18 -0400 Subject: [PATCH] Format daily --- daily.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/daily.py b/daily.py index 7a4d0dd..53429cb 100755 --- a/daily.py +++ b/daily.py @@ -1,15 +1,23 @@ #!/usr/bin/env python3 +import re import sys import time import json +import jinja2 import requests import argparse import subprocess +from textwrap import wrap + #from requests.packages.urllib3.exceptions import InsecureRequestWarning #requests.packages.urllib3.disable_warnings(InsecureRequestWarning) +weekdays = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] + +session = requests.Session() + parser = argparse.ArgumentParser() parser.add_argument('-b', '--base-url', required=True) parser.add_argument('-d', '--date', default="today") @@ -18,10 +26,52 @@ args = parser.parse_args() date = subprocess.check_output(['date','-d',args.date,'+%s']) date = float(date) date = time.localtime(date) +weekday = weekdays[date.tm_wday] date = time.strftime(r'%Y-%m-%d', date) url_template = 'https://{base_url}/rest/tempo-timesheets/3/worklogs?dateFrom={date}&dateTo={date}&expand=issue.status' url = url_template.format(base_url=args.base_url, date=date) -resp = requests.get(url, verify=False) -print(json.dumps(resp.json())) +resp = session.get(url, verify=False) +worklogs = resp.json() + + +print("\nHi,\n\n{}:\n".format(weekday)) + +for worklog in worklogs: + comment = worklog['comment'] + issue_key = worklog['issue']['key'] + issue = worklog['issue']['self'] + seconds = worklog['timeSpentSeconds'] + + r = session.get(issue, verify=False) + j = r.json() + summary = j['fields']['summary'] + status = j['fields']['status']['name'] + + seconds = int(seconds) + hours = seconds // 3600 + mins = (seconds % 3600) // 60 + time = ("{}h ".format(hours) if hours > 0 else "") + time += "{}m".format(mins) + time = time.strip() + + title = "{} {}".format(issue_key, summary) + line = "-" * len(title) + title += " ({})".format(time) + + print(" ", title) + print(" ", line) + + comment_points = re.findall(r'(?:^|\n)-\s+.*', comment) + comment_points = [re.sub('^\s*-\s+','',x) for x in comment_points] + for point in comment_points: + for i, line in enumerate(wrap(point, 40)): + if i == 0: + print(" -", line) + else: + print(" ", line) + + #print(re.split(r'(^-\s+|\n-\s+)',comment)) + print(" [{}]".format(status)) + print()