Format daily

This commit is contained in:
Andy Teijelo Pérez 2017-04-20 07:34:18 -04:00
parent 6d3615cdda
commit 1d75b5a3fa

View file

@ -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()