Skip to content

Commit a46bcf8

Browse files
committed
Added 'create_worklog' for v4
1 parent 0ef12bf commit a46bcf8

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pip install tempo-api-python-client
2222

2323
You need an API token for communicating with tempo REST APIs.
2424

25-
For v3 use
25+
### For v3 use
2626

2727
from tempoapiclient import client_v3
2828

@@ -38,14 +38,16 @@ For v3 use
3838
for i in worklogs:
3939
print(i)
4040

41-
For v4 use
41+
### For v4 use
4242

4343
from tempoapiclient import client_v4
4444

4545
tempo = client_v4.Tempo(
4646
auth_token="<your_tempo_api_key>",
4747
)
4848

49+
#### Retrieve Worklogs
50+
4951
worklogs = tempo.get_worklogs(
5052
dateFrom="2019-11-10",
5153
dateTo="2019-11-11"
@@ -55,6 +57,17 @@ For v4 use
5557
print(i)
5658

5759

60+
#### Create Worklog
61+
62+
logged_worklog = tempo.create_worklog(
63+
accountId="<your_jira_account_id>",
64+
issueId=12345,
65+
dateFrom="2019-11-11",
66+
timeSpentSeconds=3600,
67+
description="Something",
68+
startTime="17:00:00"
69+
)
70+
5871
There are also functions to retrieve `user` and `team`-specific worklogs.
5972

6073

tempoapiclient/client_v4.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,38 @@ def _resolve_date(self, value):
3737
parsed = datetime.strptime(value, r"%Y-%m-%d").date()
3838

3939
return parsed
40+
41+
def _resolve_time(self, value):
42+
_v = self.strip_hrs(value)
43+
_h = 0
44+
_m = 0
45+
_s = 0
46+
if _v.__contains__("pm"):
47+
_v = _v.replace("pm","")
48+
_h = int(_v.split(":")[0])
49+
if _h < 12:
50+
_h = _h+12
51+
elif _h == 12:
52+
_h = 0
53+
else:
54+
_h = int(_v.split(":")[0])
55+
if _h > 99:
56+
_h = int(_h/100)
57+
if _v.count(":") == 2:
58+
_m = int(_v.split(":")[1])
59+
_s = int(_v.split(":")[2])
60+
elif _v.count(":") == 1:
61+
_m = int(_v.split(":")[1])
62+
value = "{:02d}:{:02d}:{:02d}".format(_h, _m, _s)
63+
parsed = datetime.strptime(value, r"%H:%M:%S").time()
64+
return parsed
65+
66+
def strip_hrs(self, value):
67+
_hrs = ["am", "uhr", "hrs", "hours", "hour"]
68+
retval = value.lower().replace(" ","").replace(".",":")
69+
for i in _hrs:
70+
retval = retval.replace(i, "")
71+
return retval.strip()
4072

4173
def get(self, path, data=None, flags=None, params=None, headers=None, not_json_response=None, trailing=None):
4274
path_absolute = super().url_joiner(self._base_url, path)
@@ -573,6 +605,46 @@ def search_worklogs(self, dateFrom, dateTo, updatedFrom=None, authorIds=None, is
573605
url = f"/worklogs/search"
574606

575607
return self.post(url, params=params, data=data)
608+
609+
def create_worklog(self, accountId, issueId, dateFrom, timeSpentSeconds, billableSeconds=None, description=None,
610+
remainingEstimateSeconds=None, startTime=None):
611+
"""
612+
Creates a new Worklog using the provided input and returns the newly created Worklog.
613+
:param accountId:
614+
:param issueId:
615+
:param dateFrom:
616+
:param timeSpentSeconds:
617+
:param billableSeconds:
618+
:param description:
619+
:param remainingEstimateSeconds:
620+
:param startTime:
621+
"""
622+
623+
url = f"/worklogs"
624+
625+
data = {
626+
"authorAccountId": str(accountId),
627+
"issueId": int(issueId),
628+
"startDate": self._resolve_date(dateFrom).isoformat(),
629+
"timeSpentSeconds": int(timeSpentSeconds)
630+
}
631+
632+
if billableSeconds:
633+
data["billableSeconds"] = int(billableSeconds)
634+
if description:
635+
data["description"] = str(description)
636+
if remainingEstimateSeconds:
637+
data["remainingEstimateSeconds"] = int(remainingEstimateSeconds)
638+
if startTime:
639+
data["startTime"] = self._resolve_time(startTime).isoformat()
640+
641+
return self.post(url, data=data)
642+
643+
644+
645+
646+
# Customer
647+
576648
def create_customer(self, key=None, name=None, data=None):
577649
"""
578650
Create customer
@@ -608,6 +680,8 @@ def update_customer(self, key=None, name=None, data=None):
608680

609681
return self.put(url, data=data)
610682

683+
# Account
684+
611685
def create_account(self, key=None, leadAccountId=None, name=None, status=None, categoryKey=None, contactAccountId=None, customerKey=None, externalContactName=None, isGlobal=None, data=None):
612686
"""
613687
Create account

0 commit comments

Comments
 (0)