전국의 후지이 사토시 7 단 팬에게 말하고 싶은 일이있다.
16535 단어 Python3람다장기slackbotBeautifulSoup
나는 나가세 타쿠야 7 단을 좋아합니다.

언젠가 이런 날이 오면 좋네요

만든 것
내일의 공식전 전 대국 예정을 Slack에 통지하는 BOT(매일 22시에 갱신


대국 카드로 배경 이미지 변경
종류
배경 이미지
AbemaTV와 니코니코 생방송으로 방송하는 대국

AbemaTV에서 방송하는 대국

니코니코 생방송으로 방송하는 대국

NHK 컵 장기 토너먼트에서 방송하는 대국

은하전에서 방송하는 대국

일반 대국

여성기사끼리의 대국

링크 버튼

이미지 아래의 링크 버튼을 클릭 (탭)하면 브라우저에서 다음 페이지를 엽니 다

대국자 이름 버튼
기전명 버튼
Google 검색 결과 페이지 열기 (대국자 이름 + 장기로 검색)
일본 장기 연맹 공식 페이지 열기
구현된 구성

구현으로 고집한 곳
대국자명의 문자수에 맞추어, 문자의 크기를 알맞게 자동 조정
최단 문자 수 기사끼리의 대국
최장 문자수 기사끼리의 대국


picture.py
# フォントのサイズが描画領域のサイズを下回るまでループして縮小させる
while img_width < out_text_size[0] + 120 or img_height < out_text_size[1]+ 120:
font = ImageFont.truetype(text_font_family, text_max_font_size - font_size_offset)
out_text_size = draw.textsize(text, font=font)
font_size_offset += 1
w, h = font.getsize(text)
x = (img_width - w)/2
y = (img_height - h)/2
draw.text((x, y + text_height), text, fill=(text_color), font=font)
내일 대국 약속을 알리기 전에 과거 대국 일정을 모두 삭제합니다.

타임 라인에 과거의 대국 예정이 남아 있으면, 내일의 대국 예정의 개시 시점이 알기 어려운 것과, 장래적으로 Slack의 파일 업로드 수 제한에 걸려 버리므로, 과거의 대국 예정은 매일 삭제하는 구현 했습니다

채널 메시지의 history를 얻는 API를 두드리고, 얻은 데이터를 루프로 돌려 delete의 API를 두드려 줍니다

slack 메시지 일괄 삭제(python3) 참조

이미지와 링크 버튼을 하나의 부착물에

프레임(어태치먼트) 안에서
日付
画像
ボタン
의 순서로 세트 하는데 조금 고생했습니다 
라고 하는 것도, 현재 Slack의 각 API는 이런 사양이 되고 있습니다

· 이미지를 업로드하는 API는 동시에 버튼을 배치할 수 없습니다.
・버튼을 배치하는 API(이번은 Incoming Webhooks)는 이미지를 업로드할 수 없지만, 이미지의 URL을 지정하면 그 이미지를 표시할 수 있다
그래서 "이미지 전용 채널에 이미지를 업로드하고 그 URL을 Incoming WebHooks로 지정한다"라는 2 단계의 처리로 이것을 실현하기로했습니다

picture.py
result = requests.post(url="https://slack.com/api/files.upload",params=param, files=files)
json_data = result.json()
image_url = json.dumps(json_data["file"]["url_private"])
return image_url.replace("\"", "") # 画像をアップロードしてURLを返却し...
main.py
payload = {
"attachments": [
{
"fallback": fallback,
"text": text,
"image_url": image_url, # ここで指定!
"actions": [
{
"type": "button",
"name": "player1",
"text": ":bust_in_silhouette: " + row_list[2],
"url": player1,
"style": "normal",
},
{
"type": "button",
"name": "player2",
"text": ":bust_in_silhouette: " + row_list[4],
"url": player2,
"style": "normal",
},
{
"type": "button",
"name": "title",
"text": ":newspaper: " + row_list[0] ,
"url": 'https://www.shogi.or.jp' + row_list[1],
"style": "normal",
}
]
}
]
}
requests.post(boto3.client('kms').decrypt(CiphertextBlob=b64decode(os.environ['incoming_web_hook_url']))['Plaintext'], data=json.dumps(payload))
마지막으로
누구나 무료로이 채널 (#game-info)에 가입 할 수 있습니다


h tps://오. gl/후rms/DJMF와 vR2m807WpR2
(이메일 주소를 입력하면 초대 메일이 도착하므로 계정을 만드십시오

덧붙여서 방송 예정의 대국에는
@channel
에 멘션을 날리고 있으므로,
그러면 방송 예정의 대국만 Push 통지됩니다

이 BOT 소스 코드는 GitHub에 업로드되었습니다.

그럼 좋은 장기 생활을

Reference
이 문제에 관하여(전국의 후지이 사토시 7 단 팬에게 말하고 싶은 일이있다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/karmanord/items/4e537abd35bc1010ad03텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)