msg_to_slack.py
· 787 B · Python
Brut
#!/SNS/users/y8z/miniconda/envs/slack/bin/python
# -*- coding: utf-8 -*-
from slack_sdk import WebClient
import json
calib_file = "/SNS/PG3/shared/CALIBRATION/cal_config.json"
with open(calib_file, "r") as f:
calib_config = json.load(f)
dia_file = calib_config["Diamond"]
out_dir = calib_config["OutputDir"]
slack_msg = f"Calibration file generated for diamond run `{dia_file}`\n"
slack_msg += f"Check the calibration H5 file "
slack_msg += f"at, `{out_dir}`.\n"
slack_msg += "If not seeing the calibration file, "
slack_msg += "log in Analysis and run `pg3_cal` to "
slack_msg += "prepare the calibration file."
sltk = "xoxb-......" # <= Slack token starting with 'xoxb' goes here
client = WebClient(token=sltk)
client.chat_postMessage(channel="powgen-monitor", text=slack_msg)
| 1 | #!/SNS/users/y8z/miniconda/envs/slack/bin/python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | from slack_sdk import WebClient |
| 4 | import json |
| 5 | |
| 6 | calib_file = "/SNS/PG3/shared/CALIBRATION/cal_config.json" |
| 7 | |
| 8 | with open(calib_file, "r") as f: |
| 9 | calib_config = json.load(f) |
| 10 | |
| 11 | dia_file = calib_config["Diamond"] |
| 12 | out_dir = calib_config["OutputDir"] |
| 13 | |
| 14 | slack_msg = f"Calibration file generated for diamond run `{dia_file}`\n" |
| 15 | slack_msg += f"Check the calibration H5 file " |
| 16 | slack_msg += f"at, `{out_dir}`.\n" |
| 17 | slack_msg += "If not seeing the calibration file, " |
| 18 | slack_msg += "log in Analysis and run `pg3_cal` to " |
| 19 | slack_msg += "prepare the calibration file." |
| 20 | sltk = "xoxb-......" # <= Slack token starting with 'xoxb' goes here |
| 21 | client = WebClient(token=sltk) |
| 22 | client.chat_postMessage(channel="powgen-monitor", text=slack_msg) |