Skip to content

Commit

Permalink
refactor format
Browse files Browse the repository at this point in the history
  • Loading branch information
cctdaniel committed May 17, 2024
1 parent 570f182 commit 261273d
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pyth_observer/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,7 @@ async def send(self):

formatted_message = ""
for key, value in text.items():
value_str = (
f"{value:.2f}%"
if key == "deviation"
else f"{value} seconds"
if key == "stall_duration"
else f"{value:.2f}%"
)
formatted_message += (
f"*{key.capitalize().replace('_', ' ')}:* {value_str}\n"
)
formatted_message += f"*{key.capitalize().replace('_', ' ')}:* {self.format_value(key, value)}\n"

message_data = {
"chat_id": chat_id,
Expand All @@ -157,3 +148,11 @@ async def send(self):
logger.error(
f"Failed to send Telegram message: {response_text}"
)

def format_value(self, key: str, value: float) -> str:
if key == "deviation":
return f"{value:.2f}%"
elif key == "stall_duration":
return f"{value:.2f} seconds"
else:
return f"{value:.2f}"

0 comments on commit 261273d

Please sign in to comment.