Skip to content

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
FusRoman committed Jan 18, 2024
1 parent 59b841b commit 3c01421
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions fink_fat/slack_bot/slack_bot.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
import configparser
import time
import os

from fink_fat.others.utils import init_logging


def init_slackbot()->WebClient:
def init_slackbot() -> WebClient:
try:
token_slack = os.environ['ANOMALY_SLACK_TOKEN']
except KeyError as ke:
l = init_logging()
l.error("ANOMALY_SLACK_TOKEN environement variable not found !!", exc_info=1)
token_slack = os.environ["ANOMALY_SLACK_TOKEN"]
except KeyError:
logger = init_logging()
logger.error("ANOMALY_SLACK_TOKEN environement variable not found !!", exc_info=1)
client = WebClient(token=token_slack)
return client

Expand All @@ -21,25 +19,17 @@ def post_msg_on_slack(webclient: WebClient, msg: str):
logging = init_logging()
try:
webclient.chat_postMessage(
channel='#bot_asteroid_test',
text=msg,
blocks=[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": msg
}
}
]
)
channel="#bot_asteroid_test",
text=msg,
blocks=[{"type": "section", "text": {"type": "mrkdwn", "text": msg}}],
)
logging.info("Post msg on slack successfull")
except SlackApiError as e:
if e.response["ok"] is False:
logging.error("Post slack msg error", exc_info=1)

if __name__ == "__main__":

if __name__ == "__main__":
slack_client = init_slackbot()

post_msg_on_slack(slack_client, "bonjour")
post_msg_on_slack(slack_client, "bonjour")

0 comments on commit 3c01421

Please sign in to comment.