-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathnote.py
More file actions
56 lines (46 loc) · 1.96 KB
/
Copy pathnote.py
File metadata and controls
56 lines (46 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from __future__ import annotations
from datetime import datetime
from typing import Any
from alertaclient.utils import DateTime
JSON = dict[str, Any]
class Note:
def __init__(self, text: str, user: str, note_type: str | None, **kwargs: Any) -> None:
self.id = kwargs.get('id', None)
self.text = text
self.user = user
self.note_type = note_type
self.attributes = kwargs.get('attributes', None) or dict()
self.create_time = kwargs['create_time'] if 'create_time' in kwargs else datetime.utcnow()
self.update_time = kwargs.get('update_time')
self.alert = kwargs.get('alert')
self.customer = kwargs.get('customer')
@classmethod
def parse(cls, json: JSON) -> Note:
return Note(
id=json.get('id', None),
text=json.get('text', None),
user=json.get('user', None),
attributes=json.get('attributes', dict()),
note_type=json.get('type', None),
create_time=DateTime.parse(json['createTime']) if 'createTime' in json else None,
update_time=DateTime.parse(json['updateTime']) if 'updateTime' in json else None,
alert=json.get('related', {}).get('alert'),
customer=json.get('customer', None)
)
def __repr__(self) -> str:
return 'Note(id={!r}, text={!r}, user={!r}, type={!r}, customer={!r})'.format(
self.id, self.text, self.user, self.note_type, self.customer
)
def tabular(self, timezone: str | None = None) -> dict[str, Any]:
note = {
'id': self.id,
'text': self.text,
'createTime': DateTime.localtime(self.create_time, timezone),
'user': self.user,
# 'attributes': self.attributes,
'type': self.note_type,
'related': self.alert,
'updateTime': DateTime.localtime(self.update_time, timezone),
'customer': self.customer
}
return note