jira-daily/daily.py

78 lines
2.1 KiB
Python
Raw Permalink Normal View History

2017-04-13 14:57:00 -04:00
#!/usr/bin/env python3
2017-04-20 07:34:18 -04:00
import re
2017-04-13 14:57:00 -04:00
import sys
import time
import json
2017-04-20 07:34:18 -04:00
import jinja2
2017-04-13 14:57:00 -04:00
import requests
2017-04-13 15:12:48 -04:00
import argparse
2017-04-13 14:57:00 -04:00
import subprocess
2017-04-20 07:34:18 -04:00
from textwrap import wrap
2017-04-13 15:12:48 -04:00
#from requests.packages.urllib3.exceptions import InsecureRequestWarning
#requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
2017-04-13 14:57:00 -04:00
2017-04-20 07:34:18 -04:00
weekdays = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
session = requests.Session()
2017-04-13 15:12:48 -04:00
parser = argparse.ArgumentParser()
parser.add_argument('-b', '--base-url', required=True)
parser.add_argument('-d', '--date', default="today")
args = parser.parse_args()
2017-04-13 14:57:00 -04:00
2017-04-13 15:12:48 -04:00
date = subprocess.check_output(['date','-d',args.date,'+%s'])
date = float(date)
date = time.localtime(date)
2017-04-20 07:34:18 -04:00
weekday = weekdays[date.tm_wday]
2017-04-13 14:57:00 -04:00
date = time.strftime(r'%Y-%m-%d', date)
2017-04-13 15:56:06 -04:00
url_template = 'https://{base_url}/rest/tempo-timesheets/3/worklogs?dateFrom={date}&dateTo={date}&expand=issue.status'
2017-04-13 15:12:48 -04:00
url = url_template.format(base_url=args.base_url, date=date)
2017-04-13 14:57:00 -04:00
2017-04-20 07:34:18 -04:00
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()