Python에서 간단하게 slack에 경고를 날리기 (2022 새로운 방식 버전)
소개
현장에서는 이 손의 「로그를 slack에 던진다」같은 것은 벌써 완성되고 있는 것이 많지만 실제로 해본 적이 있는지 없는지는 크게 다르므로, 메모같은 것이지만 써 둔다
참고
어플리케이션의 테마 자체는 이쪽
하지만 slack의 설정 방법이 낡기 때문에,
설정 방법은 여기
의 새로운 방식으로
슬랙 측 준비
htps : // 아피. scck. 이 m/아 ps/




Webhook URL을 복사하십시오.

소스
import json
import requests
def send_message(message: str):
response = requests.post(
# webhook urlを貼る
'https://hooks.slack.com/services/cool/slack/endpoint',
data=json.dumps({
"channel": "random",
"text": message,
"icon_emoji": ":mostly_sunny:",
"username": "weather_bot"
})
)
print(response)
if __name__ == '__main__':
TODAY = 0
TOKYO = 130010
url = f'https://weather.tsukumijima.net/api/forecast/city/{TOKYO}'
weather_data = requests.get(url).json()
txt = weather_data["title"] + '\n'
txt += weather_data["forecasts"][TODAY]["date"] + '\n'
txt += weather_data["forecasts"][TODAY]["telop"] + '\n'
send_message(txt)
확인
Reference
이 문제에 관하여(Python에서 간단하게 slack에 경고를 날리기 (2022 새로운 방식 버전)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YoshitakaOkada/items/94f66dffbf46294f7b20
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
어플리케이션의 테마 자체는 이쪽

설정 방법은 여기

슬랙 측 준비
htps : // 아피. scck. 이 m/아 ps/




Webhook URL을 복사하십시오.

소스
import json
import requests
def send_message(message: str):
response = requests.post(
# webhook urlを貼る
'https://hooks.slack.com/services/cool/slack/endpoint',
data=json.dumps({
"channel": "random",
"text": message,
"icon_emoji": ":mostly_sunny:",
"username": "weather_bot"
})
)
print(response)
if __name__ == '__main__':
TODAY = 0
TOKYO = 130010
url = f'https://weather.tsukumijima.net/api/forecast/city/{TOKYO}'
weather_data = requests.get(url).json()
txt = weather_data["title"] + '\n'
txt += weather_data["forecasts"][TODAY]["date"] + '\n'
txt += weather_data["forecasts"][TODAY]["telop"] + '\n'
send_message(txt)
확인
Reference
이 문제에 관하여(Python에서 간단하게 slack에 경고를 날리기 (2022 새로운 방식 버전)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YoshitakaOkada/items/94f66dffbf46294f7b20
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import json
import requests
def send_message(message: str):
response = requests.post(
# webhook urlを貼る
'https://hooks.slack.com/services/cool/slack/endpoint',
data=json.dumps({
"channel": "random",
"text": message,
"icon_emoji": ":mostly_sunny:",
"username": "weather_bot"
})
)
print(response)
if __name__ == '__main__':
TODAY = 0
TOKYO = 130010
url = f'https://weather.tsukumijima.net/api/forecast/city/{TOKYO}'
weather_data = requests.get(url).json()
txt = weather_data["title"] + '\n'
txt += weather_data["forecasts"][TODAY]["date"] + '\n'
txt += weather_data["forecasts"][TODAY]["telop"] + '\n'
send_message(txt)
확인
Reference
이 문제에 관하여(Python에서 간단하게 slack에 경고를 날리기 (2022 새로운 방식 버전)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YoshitakaOkada/items/94f66dffbf46294f7b20
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(Python에서 간단하게 slack에 경고를 날리기 (2022 새로운 방식 버전)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/YoshitakaOkada/items/94f66dffbf46294f7b20텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)