diff --git a/README.md b/README.md
index c605896..f3e3eff 100644
--- a/README.md
+++ b/README.md
@@ -88,6 +88,7 @@ SHOW_POST_FLAGS - optional, if set to true, will show post flags in html post vi
``` curl https://pgbridge.example.com/rss/DragorWW_space?exclude_flags=video,stream,donat,clown ``` with exclude_flags parameter
``` curl https://pgbridge.example.com/rss/DragorWW_space?exclude_text=реклама,акция ``` with exclude_text parameter
``` curl https://pgbridge.example.com/rss/DragorWW_space?exclude_text="специальное предложение",акция ``` with exclude_text parameter containing phrases with spaces
+``` curl https://pgbridge.example.com/html/DragorWW_space/123?debug=true ``` with debug parameter to print raw message to logs
Warning: TG API has rate limit, and bridge will wait time before http response, if catch FloodWait exception. Increase http timeout in your client prevention timeout error. Examply, in miniflux: ENV HTTP_CLIENT_TIMEOUT=200
diff --git a/api_server.py b/api_server.py
index d44c39a..e8f4f29 100644
--- a/api_server.py
+++ b/api_server.py
@@ -443,7 +443,7 @@ def calculate_cache_stats():
@app.get("/post/html/{channel}/{post_id}", response_class=HTMLResponse)
@app.get("/html/{channel}/{post_id}/{token}", response_class=HTMLResponse)
@app.get("/post/html/{channel}/{post_id}/{token}", response_class=HTMLResponse)
-async def get_post_html(channel: str, post_id: int, token: str | None = None):
+async def get_post_html(channel: str, post_id: int, token: str | None = None, debug: bool = False):
if Config["token"]:
if token != Config["token"]:
logger.error(f"Invalid token for HTML post: {token}, expected: {Config['token']}")
@@ -453,7 +453,7 @@ async def get_post_html(channel: str, post_id: int, token: str | None = None):
try:
parser = PostParser(client.client)
- html_content = await parser.get_post(channel, post_id, 'html')
+ html_content = await parser.get_post(channel, post_id, 'html', debug)
if not html_content:
raise HTTPException(status_code=404, detail="Post not found")
return html_content
@@ -467,7 +467,7 @@ async def get_post_html(channel: str, post_id: int, token: str | None = None):
@app.get("/post/json/{channel}/{post_id}")
@app.get("/json/{channel}/{post_id}/{token}")
@app.get("/post/json/{channel}/{post_id}/{token}")
-async def get_post(channel: str, post_id: int, token: str | None = None):
+async def get_post(channel: str, post_id: int, token: str | None = None, debug: bool = False):
if Config["token"]:
if token != Config["token"]:
logger.error(f"Invalid token for JSON post: {token}, expected: {Config['token']}")
@@ -477,7 +477,7 @@ async def get_post(channel: str, post_id: int, token: str | None = None):
try:
parser = PostParser(client.client)
- json_content = await parser.get_post(channel, post_id, 'json')
+ json_content = await parser.get_post(channel, post_id, 'json', debug)
if not json_content:
raise HTTPException(status_code=404, detail="Post not found")
return json_content
diff --git a/post_parser.py b/post_parser.py
index c4ea10c..88812a2 100644
--- a/post_parser.py
+++ b/post_parser.py
@@ -59,13 +59,12 @@ class PostParser:
self.client = client
def _debug_message(self, message: Message) -> Message:
- if Config["debug"]:
- debug_message = copy.deepcopy(message)
- debug_message.sender_chat = None
- debug_message.caption_entities = None
- debug_message.reactions = None
- debug_message.entities = None
- print(debug_message)
+ debug_message = copy.deepcopy(message)
+ debug_message.sender_chat = None
+ debug_message.caption_entities = None
+ debug_message.reactions = None
+ debug_message.entities = None
+ print(debug_message)
return
def channel_name_prepare(self, channel: str):
@@ -75,13 +74,15 @@ class PostParser:
else:
return channel
- async def get_post(self, channel: str, post_id: int, output_type: str = 'json') -> Union[str, Dict[Any, Any]]:
+ async def get_post(self, channel: str, post_id: int, output_type: str = 'json', debug: bool = False) -> Union[str, Dict[Any, Any]]:
print(f"Getting post {channel}, {post_id}")
try:
channel = self.channel_name_prepare(channel)
message = await self.client.get_messages(channel, post_id)
- self._debug_message(message)
+ # Выводим отладочную информацию, если включен глобальный debug или параметр debug
+ if Config["debug"] or debug:
+ self._debug_message(message)
if not message:
logger.error(f"post_not_found: channel {channel}, post_id {post_id}")
@@ -519,12 +520,12 @@ class PostParser:
links.append(f'Open in Telegram')
links.append(f'Open in Web')
if Config['show_bridge_link']:
- links.append(f'Open in Bridge')
+ links.append(f'Open in Bridge')
else: # For channels with username
links.append(f'Open in Telegram')
links.append(f'Open in Web')
if Config['show_bridge_link']:
- links.append(f'Open in Bridge')
+ links.append(f'Open in Bridge')
second_line_parts.extend(links)
if second_line_parts: