8000 code clean up · homeylab/bookstack-file-exporter@f3cbf8b · GitHub
[go: up one dir, main page]

Skip to content

Commit f3cbf8b

Browse files
committed
code clean up
1 parent b596668 commit f3cbf8b

File tree

1 file changed

+9
-35
lines changed

1 file changed

+9
-35
lines changed

bookstack_file_exporter/archiver/page_archiver.py

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,21 @@ def __init__(self, img_meta_data: Dict[str, Union[int, str]]):
4747
self.url: str = img_meta_data['url']
4848
self.name: str = self._get_image_name()
4949
self._markdown_str = ""
50-
self.image_relative_path: str = f"./{_IMAGE_DIR_NAME}/{self.name}"
50+
self._image_relative_path: str = f"./{_IMAGE_DIR_NAME}/{self.name}"
5151

5252
def _get_image_name(self) -> str:
5353
return self.url.split('/')[-1]
54-
55-
# def _get_markdown_str(self, img_details: Dict[str, Union[int, str]]) -> str:
56-
# if 'content' in img_details:
57-
# if _MARKDOWN_STR_CHECK in img_details['content']:
58-
# print(img_details['content'][_MARKDOWN_STR_CHECK])
59-
# return self._get_md_url_str(img_details['content'][_MARKDOWN_STR_CHECK])
60-
# return ""
54+
55+
@property
56+
def image_relative_path(self):
57+
return self._image_relative_path
6158

6259
@property
6360
def markdown_str(self):
6461
return self._markdown_str
6562

6663
def set_markdown_content(self, img_details: Dict[str, Union[int, str]]):
6764
self._markdown_str = self._get_md_url_str(img_details)
68-
# @markdown_str.setter
69-
# def markdown_str(self, img_details: Dict[str, Union[int, str]]) -> str:
70-
# self._markdown_str = self._get_md_url_str(img_details)
71-
72-
73-
def get_replace_str(self) -> str:
74-
"""return str for regex replace in page md content"""
75-
# return f"[![{self.name}]({self.image_relative_path})]"
76-
return self.image_relative_path
7765

7866
@staticmethod
7967
def _get_md_url_str(img_data: Dict[str, Union[int, str]]) -> str:
@@ -185,30 +173,17 @@ def gzip_archive(self):
185173
def _update_image_links(self, page_data: bytes, image_nodes: List[ImageNode]) -> bytes:
186174
"""regex replace links to local created directories"""
187175
for img_node in image_nodes:
188-
img_meta_url = f"{self.api_urls["images"]}/{img_node.id}"
176+
img_meta_url = f"{self.api_urls['images']}/{img_node.id}"
189177
img_details = common_util.http_get_request(img_meta_url,
190178
self._headers, self.verify_ssl)
191179

192180
img_node.set_markdown_content(img_details.json())
193181
if not img_node.markdown_str:
194182
continue
195-
196-
# re_pattern_bytes = self._get_regex_expr(img_node.markdown_str)
197-
198-
# re_pattern_bytes = self._get_regex_expr(img_node.url)
199-
200183
# 1 - what to replace, 2 - replace with, 3 is the data to replace
201-
# re.sub(b'pfsense', b'lol', x.content)
202-
print(img_node.markdown_str)
203-
print(img_node.get_replace_str())
204-
page_data = re.sub(img_node.markdown_str.encode(), img_node.get_replace_str().encode(), page_data)
205-
# print(page_data)
184+
page_data = re.sub(img_node.markdown_str.encode(), img_node.image_relative_path().encode(), page_data)
206185
return page_data
207186

208-
# string to bytes
209-
# >>> k = 'lol'
210-
# >>> k.encode()
211-
212187
@property
213188
def file_extension_map(self) -> Dict[str, str]:
214189
"""file extension metadata"""
@@ -225,10 +200,9 @@ def verify_ssl(self) -> bool:
225200
return self.asset_config.verify_ssl
226201

227202
# @staticmethod
228-
# def _get_regex_expr(image_str: str) -> bytes:
203+
# def _get_regex_expr(url: str) -> bytes:
229204
# # regex_str = fr"\[\!\[^$|.*\]\({url}\)\]"
230-
# # print(regex_str)
231-
# return re.compile(image_str.encode())
205+
# return re.compile(regex_str.encode())
232206

233207
@staticmethod
234208
def _create_image_map(json_data: List[Dict[str, Union[str,int]]]) -> Dict[int, List[ImageNode]]:

0 commit comments

Comments
 (0)
0