MilanoteUnofficialApi.elements.board
1from .element import Element 2from .column import Column 3from .commentthread import CommentThread 4from .document import Document 5from .link import Link 6from .location import Location 7from .meta import Meta 8from .task import Task 9from .tasklist import TaskList 10from .card import Card 11from .file import File 12from .image import Image 13from .annotation import Annotation 14from .color_swatch import ColorSwatch 15from .sketch import Sketch 16 17import logging 18 19 20class Board(Element): 21 """ 22 A Milanote board, contains sub elements. 23 """ 24 25 id: str 26 """ID of the element.""" 27 element_type: str 28 """Type of the element.""" 29 meta: Meta 30 """Metadata of the element.""" 31 location: Location 32 """Location of the element.""" 33 title: str 34 """Title of the board.""" 35 elements: dict[str, list[Element]] 36 """Elements contained in the board.""" 37 38 def __init__(self, data: dict, elements_data: dict = None, comments_data: dict = None): 39 super().__init__(data) 40 self.title = data["content"]["title"] 41 self.elements = { 42 "TASK": [], 43 "TASK_LIST": [], 44 "DOCUMENT": [], 45 "LINK": [], 46 "COLUMN": [], 47 "BOARD": [], 48 "COMMENT_THREAD": [], 49 "CARD": [], 50 "FILE": [], 51 "IMAGE": [], 52 "ANNOTATION": [], 53 "COLOR_SWATCH": [], 54 "SKETCH": [], 55 "ALIAS": [], 56 } 57 if elements_data is not None: 58 self.init_elements(elements_data, comments_data) 59 60 def init_elements(self, elements_data: dict, comments_data: dict = None): 61 """ 62 Initialize the elements contained in the board. 63 """ 64 comments_data_by_thread_id = {} 65 if comments_data is not None: 66 comments_data_by_thread_id = self.init_comments(comments_data) 67 if elements_data is None: 68 return 69 for element_data in elements_data.values(): 70 element_type = element_data["elementType"] 71 if element_type == "TASK": 72 self.elements["TASK"].append(Task(element_data)) 73 elif element_type == "TASK_LIST": 74 self.elements["TASK_LIST"].append(TaskList(element_data)) 75 elif element_type == "DOCUMENT": 76 self.elements["DOCUMENT"].append(Document(element_data)) 77 elif element_type == "LINK": 78 self.elements["LINK"].append(Link(element_data)) 79 elif element_type == "COLUMN": 80 self.elements["COLUMN"].append(Column(element_data)) 81 elif element_type == "BOARD": 82 self.elements["BOARD"].append(Board(element_data)) 83 elif element_type == "COMMENT_THREAD": 84 self.elements["COMMENT_THREAD"].append( 85 CommentThread(element_data, comments_data_by_thread_id.get(element_data["id"], None))) 86 elif element_type == "CARD": 87 self.elements["CARD"].append(Card(element_data)) 88 elif element_type == "FILE": 89 self.elements["FILE"].append(File(element_data)) 90 elif element_type == "IMAGE": 91 self.elements["IMAGE"].append(Image(element_data)) 92 elif element_type == "ANNOTATION": 93 self.elements["ANNOTATION"].append(Annotation(element_data)) 94 elif element_type == "COLOR_SWATCH": 95 self.elements["COLOR_SWATCH"].append(ColorSwatch(element_data)) 96 elif element_type == "SKETCH": 97 self.elements["SKETCH"].append(Sketch(element_data)) 98 elif element_type == "ALIAS": 99 element_data["content"]["title"] = element_data["content"].get("originalTitle", None) 100 self.elements["ALIAS"].append(Board(element_data)) 101 else: 102 self.elements.setdefault(element_type, []).append(element_data) 103 logging.warning( 104 f"Unknown element type: {element_type}, saved as dict in self.elements['{element_type}']") 105 106 def init_comments(self, comments_data: dict = None) -> dict[str, list[dict]]: 107 """ 108 Create a new dict for the comments as ("parentId", list[dict]) pair to add to ClassVar[CommentThread]. 109 """ 110 if comments_data is None: 111 return {} 112 comments_data_by_thread_id = {} 113 for comment_data in comments_data.values(): 114 thread_id = comment_data["threadId"] 115 if thread_id not in comments_data_by_thread_id: 116 comments_data_by_thread_id[thread_id] = [] 117 comments_data_by_thread_id[thread_id].append(comment_data) 118 return comments_data_by_thread_id 119 120 def __repr__(self): 121 return f"Board(id='{self.id}', title='{self.title}')"
21class Board(Element): 22 """ 23 A Milanote board, contains sub elements. 24 """ 25 26 id: str 27 """ID of the element.""" 28 element_type: str 29 """Type of the element.""" 30 meta: Meta 31 """Metadata of the element.""" 32 location: Location 33 """Location of the element.""" 34 title: str 35 """Title of the board.""" 36 elements: dict[str, list[Element]] 37 """Elements contained in the board.""" 38 39 def __init__(self, data: dict, elements_data: dict = None, comments_data: dict = None): 40 super().__init__(data) 41 self.title = data["content"]["title"] 42 self.elements = { 43 "TASK": [], 44 "TASK_LIST": [], 45 "DOCUMENT": [], 46 "LINK": [], 47 "COLUMN": [], 48 "BOARD": [], 49 "COMMENT_THREAD": [], 50 "CARD": [], 51 "FILE": [], 52 "IMAGE": [], 53 "ANNOTATION": [], 54 "COLOR_SWATCH": [], 55 "SKETCH": [], 56 "ALIAS": [], 57 } 58 if elements_data is not None: 59 self.init_elements(elements_data, comments_data) 60 61 def init_elements(self, elements_data: dict, comments_data: dict = None): 62 """ 63 Initialize the elements contained in the board. 64 """ 65 comments_data_by_thread_id = {} 66 if comments_data is not None: 67 comments_data_by_thread_id = self.init_comments(comments_data) 68 if elements_data is None: 69 return 70 for element_data in elements_data.values(): 71 element_type = element_data["elementType"] 72 if element_type == "TASK": 73 self.elements["TASK"].append(Task(element_data)) 74 elif element_type == "TASK_LIST": 75 self.elements["TASK_LIST"].append(TaskList(element_data)) 76 elif element_type == "DOCUMENT": 77 self.elements["DOCUMENT"].append(Document(element_data)) 78 elif element_type == "LINK": 79 self.elements["LINK"].append(Link(element_data)) 80 elif element_type == "COLUMN": 81 self.elements["COLUMN"].append(Column(element_data)) 82 elif element_type == "BOARD": 83 self.elements["BOARD"].append(Board(element_data)) 84 elif element_type == "COMMENT_THREAD": 85 self.elements["COMMENT_THREAD"].append( 86 CommentThread(element_data, comments_data_by_thread_id.get(element_data["id"], None))) 87 elif element_type == "CARD": 88 self.elements["CARD"].append(Card(element_data)) 89 elif element_type == "FILE": 90 self.elements["FILE"].append(File(element_data)) 91 elif element_type == "IMAGE": 92 self.elements["IMAGE"].append(Image(element_data)) 93 elif element_type == "ANNOTATION": 94 self.elements["ANNOTATION"].append(Annotation(element_data)) 95 elif element_type == "COLOR_SWATCH": 96 self.elements["COLOR_SWATCH"].append(ColorSwatch(element_data)) 97 elif element_type == "SKETCH": 98 self.elements["SKETCH"].append(Sketch(element_data)) 99 elif element_type == "ALIAS": 100 element_data["content"]["title"] = element_data["content"].get("originalTitle", None) 101 self.elements["ALIAS"].append(Board(element_data)) 102 else: 103 self.elements.setdefault(element_type, []).append(element_data) 104 logging.warning( 105 f"Unknown element type: {element_type}, saved as dict in self.elements['{element_type}']") 106 107 def init_comments(self, comments_data: dict = None) -> dict[str, list[dict]]: 108 """ 109 Create a new dict for the comments as ("parentId", list[dict]) pair to add to ClassVar[CommentThread]. 110 """ 111 if comments_data is None: 112 return {} 113 comments_data_by_thread_id = {} 114 for comment_data in comments_data.values(): 115 thread_id = comment_data["threadId"] 116 if thread_id not in comments_data_by_thread_id: 117 comments_data_by_thread_id[thread_id] = [] 118 comments_data_by_thread_id[thread_id].append(comment_data) 119 return comments_data_by_thread_id 120 121 def __repr__(self): 122 return f"Board(id='{self.id}', title='{self.title}')"
A Milanote board, contains sub elements.
Board(data: dict, elements_data: dict = None, comments_data: dict = None)
39 def __init__(self, data: dict, elements_data: dict = None, comments_data: dict = None): 40 super().__init__(data) 41 self.title = data["content"]["title"] 42 self.elements = { 43 "TASK": [], 44 "TASK_LIST": [], 45 "DOCUMENT": [], 46 "LINK": [], 47 "COLUMN": [], 48 "BOARD": [], 49 "COMMENT_THREAD": [], 50 "CARD": [], 51 "FILE": [], 52 "IMAGE": [], 53 "ANNOTATION": [], 54 "COLOR_SWATCH": [], 55 "SKETCH": [], 56 "ALIAS": [], 57 } 58 if elements_data is not None: 59 self.init_elements(elements_data, comments_data)
elements: dict[str, list[MilanoteUnofficialApi.elements.element.Element]]
Elements contained in the board.
def
init_elements(self, elements_data: dict, comments_data: dict = None):
61 def init_elements(self, elements_data: dict, comments_data: dict = None): 62 """ 63 Initialize the elements contained in the board. 64 """ 65 comments_data_by_thread_id = {} 66 if comments_data is not None: 67 comments_data_by_thread_id = self.init_comments(comments_data) 68 if elements_data is None: 69 return 70 for element_data in elements_data.values(): 71 element_type = element_data["elementType"] 72 if element_type == "TASK": 73 self.elements["TASK"].append(Task(element_data)) 74 elif element_type == "TASK_LIST": 75 self.elements["TASK_LIST"].append(TaskList(element_data)) 76 elif element_type == "DOCUMENT": 77 self.elements["DOCUMENT"].append(Document(element_data)) 78 elif element_type == "LINK": 79 self.elements["LINK"].append(Link(element_data)) 80 elif element_type == "COLUMN": 81 self.elements["COLUMN"].append(Column(element_data)) 82 elif element_type == "BOARD": 83 self.elements["BOARD"].append(Board(element_data)) 84 elif element_type == "COMMENT_THREAD": 85 self.elements["COMMENT_THREAD"].append( 86 CommentThread(element_data, comments_data_by_thread_id.get(element_data["id"], None))) 87 elif element_type == "CARD": 88 self.elements["CARD"].append(Card(element_data)) 89 elif element_type == "FILE": 90 self.elements["FILE"].append(File(element_data)) 91 elif element_type == "IMAGE": 92 self.elements["IMAGE"].append(Image(element_data)) 93 elif element_type == "ANNOTATION": 94 self.elements["ANNOTATION"].append(Annotation(element_data)) 95 elif element_type == "COLOR_SWATCH": 96 self.elements["COLOR_SWATCH"].append(ColorSwatch(element_data)) 97 elif element_type == "SKETCH": 98 self.elements["SKETCH"].append(Sketch(element_data)) 99 elif element_type == "ALIAS": 100 element_data["content"]["title"] = element_data["content"].get("originalTitle", None) 101 self.elements["ALIAS"].append(Board(element_data)) 102 else: 103 self.elements.setdefault(element_type, []).append(element_data) 104 logging.warning( 105 f"Unknown element type: {element_type}, saved as dict in self.elements['{element_type}']")
Initialize the elements contained in the board.
def
init_comments(self, comments_data: dict = None) -> dict[str, list[dict]]:
107 def init_comments(self, comments_data: dict = None) -> dict[str, list[dict]]: 108 """ 109 Create a new dict for the comments as ("parentId", list[dict]) pair to add to ClassVar[CommentThread]. 110 """ 111 if comments_data is None: 112 return {} 113 comments_data_by_thread_id = {} 114 for comment_data in comments_data.values(): 115 thread_id = comment_data["threadId"] 116 if thread_id not in comments_data_by_thread_id: 117 comments_data_by_thread_id[thread_id] = [] 118 comments_data_by_thread_id[thread_id].append(comment_data) 119 return comments_data_by_thread_id
Create a new dict for the comments as ("parentId", list[dict]) pair to add to ClassVar[CommentThread].