Skip to content

Commit

Permalink
Change the format of the message sent to slack
Browse files Browse the repository at this point in the history
Don’t include the date in the message.
  • Loading branch information
caarmen committed May 8, 2023
1 parent 7f48563 commit 2ec5635
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 8 deletions.
2 changes: 0 additions & 2 deletions withingsslack/services/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import dataclasses
from datetime import datetime


@dataclasses.dataclass
class WeightData:
weight_kg: float
date: datetime
slack_alias: str
5 changes: 2 additions & 3 deletions withingsslack/services/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@


def post_weight(weight_data: WeightData):
date_str = weight_data.date.strftime("%a %d %b %Y, %H:%M")
message = (
f"<@{weight_data.slack_alias}> weighed in at "
+ f"{weight_data.weight_kg:.2f} kg on {date_str}."
f"New weight from <@{weight_data.slack_alias}>: "
+ f"{weight_data.weight_kg:.2f} kg."
)
requests.post(
url=settings.slack_webhook_url,
Expand Down
3 changes: 0 additions & 3 deletions withingsslack/services/withings/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
import logging
from typing import Optional

Expand Down Expand Up @@ -60,10 +59,8 @@ def get_last_weight(
if measures:
last_measure = measures[0]
weight_kg = last_measure["value"] * pow(10, last_measure["unit"])
measure_date = datetime.datetime.fromtimestamp(last_measuregrp_item["date"])
return svc_models.WeightData(
weight_kg=weight_kg,
date=measure_date,
slack_alias=user.slack_alias,
)
return None

0 comments on commit 2ec5635

Please sign in to comment.