From 1fb10b9c942ee7d2fd1947d3265cc95cb22d8e6a Mon Sep 17 00:00:00 2001 From: Seok Won <ikr@kakao.com> Date: Wed, 23 Dec 2020 16:44:05 +0900 Subject: [PATCH] Remove unused exception --- python/src/AjouSlackConsumer.py | 34 ++++++++++------------- python/src/avro/AjouSlackConsumerAvro.py | 35 ++++++++++-------------- 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/python/src/AjouSlackConsumer.py b/python/src/AjouSlackConsumer.py index 972d608..d94ad8a 100644 --- a/python/src/AjouSlackConsumer.py +++ b/python/src/AjouSlackConsumer.py @@ -51,26 +51,20 @@ try: except: app_msg = json.loads(msg.value()) - try: - title = app_msg["TITLE"] - date = app_msg["DATE"] - href = app_msg["LINK"] - writer = app_msg["WRITER"] - - channel = "아주대" # C01G2CR5MEE - # TODO: 학사면 좀 더 중요하게? - text = ":star: `%s` 새로운 공지!\n>%s: %s\n>링크: <%s|공지 확인하기>" % ( - date, - writer, - title, - href, - ) - print('\nSending message "%s" to channel %s' % (text, channel)) - except SlackApiError as e: - print("Failed to get channel/text from message.") - print(e.response["error"]) - channel = "kafka" - text = msg.value() + title = app_msg["TITLE"] + date = app_msg["DATE"] + href = app_msg["LINK"] + writer = app_msg["WRITER"] + + channel = "아주대" # C01G2CR5MEE + # TODO: 학사면 좀 더 중요하게? + text = ":star: `%s` 새로운 공지!\n>%s: %s\n>링크: <%s|공지 확인하기>" % ( + date, + writer, + title, + href, + ) + print('\nSending message "%s" to channel %s' % (text, channel)) try: sc_response = sc.chat_postMessage( diff --git a/python/src/avro/AjouSlackConsumerAvro.py b/python/src/avro/AjouSlackConsumerAvro.py index 146b9e8..630f285 100644 --- a/python/src/avro/AjouSlackConsumerAvro.py +++ b/python/src/avro/AjouSlackConsumerAvro.py @@ -62,30 +62,25 @@ try: rb = BytesIO(message) app_msg = schemaless_reader(rb, parsed_schema) # read one record - try: - title = app_msg["title"] - date = app_msg["date"] - href = app_msg["link"] - writer = app_msg["writer"] - - channel = "아주대" # C01G2CR5MEE - text = ":star: `%s` 새로운 공지!\n>%s: %s\n>링크: <%s|공지 확인하기>" % ( - date, - writer, - title, - href, - ) - print('\nSending message "%s" to channel %s' % (text, channel)) - except SlackApiError as e: - print("Failed to get channel/text from message.") - print(e.response["error"]) - channel = "kafka" - text = msg.value() + + title = app_msg["title"] + date = app_msg["date"] + href = app_msg["link"] + writer = app_msg["writer"] + + channel = "아주대" # C01G2CR5MEE + text = ":star: `%s` 새로운 공지!\n>%s: %s\n>링크: <%s|공지 확인하기>" % ( + date, + writer, + title, + href, + ) + print('\nSending message "%s" to channel %s' % (text, channel)) try: sc_response = sc.chat_postMessage( channel=channel, text=text, as_user=True, username="아주대 공지 봇" - ) # as_user은 new slack app에서 작동 안 함 + ) # as_user won't work with new slack app except SlackApiError as e: assert e.response["ok"] is False -- GitLab