diff --git a/python/src/AjouSlackConsumer.py b/python/src/AjouSlackConsumer.py index 972d6081d25494f3476741cfdd75ec3571f8ab78..d94ad8a3746a52d3fd46ee0f63d1751ea4b30851 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 146b9e8006e604663ee4541ab073c6fd5c439ca9..630f2858252a87bde7b7e94027a765f3b2c1d58a 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