daily.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. import re
  3. import sys
  4. import time
  5. import json
  6. import jinja2
  7. import requests
  8. import argparse
  9. import subprocess
  10. from textwrap import wrap
  11. #from requests.packages.urllib3.exceptions import InsecureRequestWarning
  12. #requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
  13. weekdays = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
  14. session = requests.Session()
  15. parser = argparse.ArgumentParser()
  16. parser.add_argument('-b', '--base-url', required=True)
  17. parser.add_argument('-d', '--date', default="today")
  18. args = parser.parse_args()
  19. date = subprocess.check_output(['date','-d',args.date,'+%s'])
  20. date = float(date)
  21. date = time.localtime(date)
  22. weekday = weekdays[date.tm_wday]
  23. date = time.strftime(r'%Y-%m-%d', date)
  24. url_template = 'https://{base_url}/rest/tempo-timesheets/3/worklogs?dateFrom={date}&dateTo={date}&expand=issue.status'
  25. url = url_template.format(base_url=args.base_url, date=date)
  26. resp = session.get(url, verify=False)
  27. worklogs = resp.json()
  28. print("\nHi,\n\n{}:\n".format(weekday))
  29. for worklog in worklogs:
  30. comment = worklog['comment']
  31. issue_key = worklog['issue']['key']
  32. issue = worklog['issue']['self']
  33. seconds = worklog['timeSpentSeconds']
  34. r = session.get(issue, verify=False)
  35. j = r.json()
  36. summary = j['fields']['summary']
  37. status = j['fields']['status']['name']
  38. seconds = int(seconds)
  39. hours = seconds // 3600
  40. mins = (seconds % 3600) // 60
  41. time = ("{}h ".format(hours) if hours > 0 else "")
  42. time += "{}m".format(mins)
  43. time = time.strip()
  44. title = "{} {}".format(issue_key, summary)
  45. line = "-" * len(title)
  46. title += " ({})".format(time)
  47. print(" ", title)
  48. print(" ", line)
  49. comment_points = re.findall(r'(?:^|\n)-\s+.*', comment)
  50. comment_points = [re.sub('^\s*-\s+','',x) for x in comment_points]
  51. for point in comment_points:
  52. for i, line in enumerate(wrap(point, 40)):
  53. if i == 0:
  54. print(" -", line)
  55. else:
  56. print(" ", line)
  57. #print(re.split(r'(^-\s+|\n-\s+)',comment))
  58. print(" [{}]".format(status))
  59. print()