From 26c97b302f29f21a4005e2f0e857e622bd832d52 Mon Sep 17 00:00:00 2001 From: SangHyungKim <40757434+nakru03@users.noreply.github.com> Date: Thu, 11 Jul 2019 16:33:25 +0900 Subject: [PATCH 1/5] [Add]Craw_image_in_url --- .gitignore | 1 + __pycache__/secrete.cpython-37.pyc | Bin 203 -> 249 bytes index.py | 63 +++++++++++++++++++---------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 656ad45..e55c4e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ secrete.py +ngrok.exe \ No newline at end of file diff --git a/__pycache__/secrete.cpython-37.pyc b/__pycache__/secrete.cpython-37.pyc index 57b2fd4428bc25f45b68363607faf4e7cdb2a43d..c028a677e5fac0469c3db73149136bc8cbb8c9bc 100644 GIT binary patch delta 170 zcmX@j_>+;>iIv6wIK>9Ho$woSKwkY-nU*kd~BcVq{@x zX=Gw(ZkcLgU~FJuW@%hyUXfpsq-$njX=Y|=U}k1!U;*M78JL8kb~+ zxfhzI=9`r#dRBR*WR?Ub75iy2-D1s8EG@~n#ha8^oS7V7oSIyeT9Uewfv<=e=o&Eb OODn}{V!Q0b)d~P0hA=e% delta 124 zcmey#c$$&diI music` 과 같이 멘션해주세요." +# def _crawl_music_chart(text): +# if not "music" in text: +# return "`@<봇이름> music` 과 같이 멘션해주세요." - url = "https://music.bugs.co.kr/chart" +# url = "https://music.bugs.co.kr/chart" - sourcecode = urllib.request.urlopen(url).read() - soup = BeautifulSoup(sourcecode, "html.parser") +# sourcecode = urllib.request.urlopen(url).read() +# soup = BeautifulSoup(sourcecode, "html.parser") - keywords = [] - title = soup.find_all("p", class_="title") - artist = soup.find_all("p", class_="artist") - for i in range(10): - keywords.append(str(i+1)+"위 : " + title[i].get_text().strip() + " / " + artist[i].get_text().strip()) +# keywords = [] +# title = soup.find_all("p", class_="title") +# artist = soup.find_all("p", class_="artist") +# for i in range(10): +# keywords.append(str(i+1)+"위 : " + title[i].get_text().strip() + " / " + artist[i].get_text().strip()) - # 한글 지원을 위해 앞에 unicode u를 붙혀준다. - return u'\n'.join(keywords) +# # 한글 지원을 위해 앞에 unicode u를 붙혀준다. +# return u'\n'.join(keywords) +def crawl_image_in_url(text): + #print(text[13:]) + text.strip() + + url = "https://haemukja.com/recipes?utf8=%E2%9C%93&sort=rlv&name=" + parse.quote(text) #임의 URL 현: 볶음밥. + source_code = urllib.request.urlopen(url).read() + soup = BeautifulSoup(source_code, "html.parser") + image_source = [] + image_blocks = [] + for src_source in soup.find_all("a", class_="call_recipe thmb"): + image_source.append(src_source.find("img").get("src")) + #print(image_source) + for block in range(len(image_source)): + image_blocks.append(ImageBlock(image_url = image_source[block],alt_text="이미지가안뜰때보이는문구")) + #print(image_blocks) + return (image_blocks) # 챗봇이 멘션을 받았을 경우 @slack_events_adaptor.on("app_mention") def app_mentioned(event_data): channel = event_data["event"]["channel"] text = event_data["event"]["text"] - - message = _crawl_music_chart(text) + message = crawl_image_in_url(text) slack_web_client.chat_postMessage( - channel=channel, - text=message + channel=channel, + blocks=extract_json(message) ) + # message = _crawl_music_chart(text) + # slack_web_client.chat_postMessage( + # channel=channel, + # text=message + # ) # slack_web_client.chat_postMessage( # channel = event_data["event"]["channel"], # text = " => 네이버입니다" # # text = "*진한 글씨* _비스듬한 글씨_ ~취소선~ `print(source code)`" # ) - + #이미지 출력을 위한 프로세싱. # block1 = ImageBlock(image_url="https://previews.123rf.com/images/isselee/isselee1101/isselee110100100/8652164-%ED%9D%B0%EC%83%89-%EB%B0%B0%EA%B2%BD-%EC%95%9E%EC%9D%98-%ED%86%A0%EB%81%BC-%ED%86%A0%EB%81%BC.jpg",alt_text="이미지가안뜰때보이는문구") # block2 = SectionBlock(fields=["text1", "text2"]) # my_blocks= [block1, block2] From 1c008850d91b58523aeba8d6f122e34a1957cb59 Mon Sep 17 00:00:00 2001 From: SangHyungKim <40757434+nakru03@users.noreply.github.com> Date: Thu, 11 Jul 2019 16:56:21 +0900 Subject: [PATCH 2/5] [Modify] Delete music method --- __pycache__/secrete.cpython-37.pyc | Bin 249 -> 251 bytes index.py | 71 +++-------------------------- 2 files changed, 6 insertions(+), 65 deletions(-) diff --git a/__pycache__/secrete.cpython-37.pyc b/__pycache__/secrete.cpython-37.pyc index c028a677e5fac0469c3db73149136bc8cbb8c9bc..e755ebe2dbcb7ef21e4e46521a9a6b702e4408ad 100644 GIT binary patch delta 58 zcmey#_?wZ}iI+;>iI music` 과 같이 멘션해주세요." - -# url = "https://music.bugs.co.kr/chart" - -# sourcecode = urllib.request.urlopen(url).read() -# soup = BeautifulSoup(sourcecode, "html.parser") - -# keywords = [] -# title = soup.find_all("p", class_="title") -# artist = soup.find_all("p", class_="artist") -# for i in range(10): -# keywords.append(str(i+1)+"위 : " + title[i].get_text().strip() + " / " + artist[i].get_text().strip()) - -# # 한글 지원을 위해 앞에 unicode u를 붙혀준다. -# return u'\n'.join(keywords) - def crawl_image_in_url(text): #print(text[13:]) text.strip() - url = "https://haemukja.com/recipes?utf8=%E2%9C%93&sort=rlv&name=" + parse.quote(text) #임의 URL 현: 볶음밥. + url = "https://haemukja.com/recipes?utf8=%E2%9C%93&sort=rlv&name=%EB%B3%B6%EC%9D%8C%EB%B0%A5" #+ #parse.quote(text) #임의 URL 현: 볶음밥. source_code = urllib.request.urlopen(url).read() soup = BeautifulSoup(source_code, "html.parser") @@ -74,7 +55,7 @@ def crawl_image_in_url(text): for src_source in soup.find_all("a", class_="call_recipe thmb"): image_source.append(src_source.find("img").get("src")) - #print(image_source) + print(image_source) for block in range(len(image_source)): image_blocks.append(ImageBlock(image_url = image_source[block],alt_text="이미지가안뜰때보이는문구")) #print(image_blocks) @@ -85,53 +66,13 @@ def crawl_image_in_url(text): def app_mentioned(event_data): channel = event_data["event"]["channel"] text = event_data["event"]["text"] + message = crawl_image_in_url(text) slack_web_client.chat_postMessage( channel=channel, blocks=extract_json(message) ) - # message = _crawl_music_chart(text) - # slack_web_client.chat_postMessage( - # channel=channel, - # text=message - # ) - - # slack_web_client.chat_postMessage( - # channel = event_data["event"]["channel"], - # text = " => 네이버입니다" - # # text = "*진한 글씨* _비스듬한 글씨_ ~취소선~ `print(source code)`" - # ) - #이미지 출력을 위한 프로세싱. - # block1 = ImageBlock(image_url="https://previews.123rf.com/images/isselee/isselee1101/isselee110100100/8652164-%ED%9D%B0%EC%83%89-%EB%B0%B0%EA%B2%BD-%EC%95%9E%EC%9D%98-%ED%86%A0%EB%81%BC-%ED%86%A0%EB%81%BC.jpg",alt_text="이미지가안뜰때보이는문구") - # block2 = SectionBlock(fields=["text1", "text2"]) - # my_blocks= [block1, block2] - # slack_web_client.chat_postMessage( - # channel=channel, - # blocks=extract_json(my_blocks) - # ) - - # 다른 사람이 메시지를 올렸을 때, 그 사람에게만 답장하기 - # 참고: https://api.slack.com/methods/chat.postEphemeral - # slack_web_client.chat_postEphemeral( - # channel=channel, - # user=event_data["event"]["user"], - # text="조용히 하세요!" - # ) - - ## name으로 id값 받아오기 - # text = ["slackbot", "hyena", "qkrjh0904"] - # response = slack_web_client.users_list() - # for user in response["members"]: - # if user["name"] in text: - # slack_web_client.chat_postMessage( - # channel = channel, - # text = user["name"] + " : " + user["id"] - # ) - # slack_web_client.chat_postEphemeral( - # channel="channel", user=user_id, text="뭐하고 있니?" - # ) - -# / 로 접속하면 서버가 준비되었다고 알려줍니다. + @app.route("/", methods=["GET"]) def index(): return "

Server is ready.

" From 0f138a89f9f56fa0b2ed06972b967add0c10bf4f Mon Sep 17 00:00:00 2001 From: SangHyungKim <40757434+nakru03@users.noreply.github.com> Date: Thu, 11 Jul 2019 17:57:21 +0900 Subject: [PATCH 3/5] [Add] hi_function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 미완성 집에서 완성하기 --- hi_funtion.py | 2 ++ index.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 hi_funtion.py diff --git a/hi_funtion.py b/hi_funtion.py new file mode 100644 index 0000000..9c6e017 --- /dev/null +++ b/hi_funtion.py @@ -0,0 +1,2 @@ +def hi_funtion(): + for i in range: \ No newline at end of file diff --git a/index.py b/index.py index d1ff261..4f92b5f 100644 --- a/index.py +++ b/index.py @@ -6,7 +6,7 @@ ####################################################################################### import secrete - +import Python_Slack_Chatbot_Project.hi_funtion ####################################################################################### # # # # From 4d434065d177549f15615f3782c490ef772a0856 Mon Sep 17 00:00:00 2001 From: SangHyung Kim Date: Thu, 11 Jul 2019 22:17:40 +0900 Subject: [PATCH 4/5] [Add]Re_compiler_function --- hi_funtion.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hi_funtion.py b/hi_funtion.py index 9c6e017..b9c9de6 100644 --- a/hi_funtion.py +++ b/hi_funtion.py @@ -1,2 +1,4 @@ -def hi_funtion(): - for i in range: \ No newline at end of file +import re + +def hi_funtion(text): + if text not in re.compile('[^ ㄱ-ㅣ가-힣]+') \ No newline at end of file From 8c9c837a7bbe6ed27c457221ca3307daf15850bd Mon Sep 17 00:00:00 2001 From: SangHyung Kim Date: Thu, 11 Jul 2019 22:18:00 +0900 Subject: [PATCH 5/5] [Add]UrlEncoding_function --- urlParse.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 urlParse.py diff --git a/urlParse.py b/urlParse.py new file mode 100644 index 0000000..e69de29