Coverage for ajallaan/worklog.py: 0.00%
32 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 15:19:53 +00:00
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 15:19:53 +00:00
1"""In due time (Finnish: ajallaan) - reporting on worklog entries of some ticket system - fetch worklog"""
3import datetime as dti
4import json
5from typing import no_type_check
7import httpx
8from ajallaan import ENCODING, log
10TS_FORMAT = '%Y-%m-%d %H:%M:%S.%f +00:00'
11TS_FORMAT_SLUG = '%Y%m%dT%H%M%SZ'
14@no_type_check
15def behind_the_moon():
16 """Spike content in here or empty (goal)."""
17 end_dd = {
18 '01': '31',
19 '02': '28',
20 '03': '31',
21 '04': '30',
22 '05': '31',
23 '06': '30',
24 '07': '31',
25 '08': '31',
26 '09': '30',
27 '10': '31',
28 '11': '30',
29 '12': '31',
30 }
31 to_date = dti.datetime.now(tz=dti.timezone.utc).strftime(TS_FORMAT_SLUG)
32 year = 2023
33 mm = '03'
34 end_mm_dd = end_dd[mm]
35 user = 'thewun'
36 token = None
37 max_results = 1000
38 wl_user = user
39 protocol = 'https'
40 host = 'example.com'
41 api_root = '/rest/com.deniz.jira.worklog/1.0/timesheet/'
42 perspective = 'user'
43 url = (
44 f'{protocol}://{host}{api_root}{perspective}?'
45 f'targetKey={wl_user}&startDate={year}-{mm}-1&endDate={year}-{mm}-{end_mm_dd}&maxResults={max_results}'
46 )
48 log.info(f'Using URL ({url}) for ({year}-{mm}) ...')
49 try:
50 r = httpx.get(url, auth=(user, token))
51 except httpx.RequestError as exc:
52 log.error(f'An error occurred while requesting {exc.request.url!r}.')
54 fname = f'worklog-monthly-{year}-{mm}-to-date-{to_date}.json'
55 with open(fname, 'wt', encoding=ENCODING) as handle:
56 json.dump(r.json(), handle)
58 log.info(f'wrote worklog data to ({fname})')