78 lines
2.1 KiB
Python
Executable file
78 lines
2.1 KiB
Python
Executable file
#!/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")
|
|
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 = 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()
|