Toggle navigation
Toggle navigation
This project
Loading...
Sign in
wlstp8473
/
telegram_Messenger_Chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
wlstp8473
2021-06-10 14:42:21 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dd1c2fcbaba364743bd9d408770b7ee4f24dc0b2
dd1c2fcb
1 parent
bd9fa0bf
search_restaurant with telegram 에러 수정
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
14 deletions
search_restaurant.py
search_restaurant.py
View file @
dd1c2fc
...
...
@@ -5,6 +5,10 @@ import requests
from
pprint
import
pprint
from
io
import
StringIO
#return_print 하기 위해
import
telegram
from
telegram.ext
import
Updater
from
telegram.ext
import
MessageHandler
,
Filters
class
KakaoLocalAPI
:
"""
Kakao Local API 컨트롤러
...
...
@@ -65,23 +69,15 @@ x = 126.98083352703802 #내 위치 위도와 경도
y
=
37.39403042340368
radius
=
1
#반경 km 검색
## Request
result_5
=
kakao
.
search_keyword
(
query
,
x
,
y
,
radius
)
# + json파일 확인해보기 이후 데이터를 추출해야함
#json_string = json.dumps(result_5, indent=2)
#print(json_string)
#json파일 특정 키워드 추출
#추출할 리스트 place_name, place_url, x, y (x y는 위치임), 검색키워드, 선택 지역(위치)
#from pprint import pprint
...
...
@@ -93,7 +89,7 @@ selected_region= "검색 위치: " +same_name_list[2]
total_count
=
{
result_5
[
'meta'
][
'total_count'
]}
#set은 파싱이 불가능하기 때문에 list나 튜플로 바꿔야함, list로 바꾼 후 인덱스를 활용하여 int로 바꾼 후 문자열과 더하기 위해 str로 형변환
total_count_list
=
list
(
total_count
)
total_count
=
"총 검색 개수: "
+
str
(
total_count_list
[
0
])
#print(keyword) #메제지들은 텔레그렘 봇으로 보내기!!
#print(keyword) #
밑 코드에서
메제지들은 텔레그렘 봇으로 보내기!!
#print(selected_region)
#print(total_count)
...
...
@@ -110,6 +106,7 @@ phone_list = [ x_['phone'] for x_ in result_5['documents']]
#print('------')
place_url_list
=
[
x_
[
'place_url'
]
for
x_
in
result_5
[
'documents'
]]
#print(place_url_list)
#print('------')
...
...
@@ -117,21 +114,24 @@ place_url_list = [ x_['place_url'] for x_ in result_5['documents']]
#print(x_list) 위치 시각화 할때 사용
x_list
=
[
x_
[
'x'
]
for
x_
in
result_5
[
'documents'
]]
y_list
=
[
x_
[
'y'
]
for
x_
in
result_5
[
'documents'
]]
#print(y_list)
#print(x_list)
#print('------')
road_address_name_list
=
[
x_
[
'road_address_name'
]
for
x_
in
result_5
[
'documents'
]]
#print(road_address_name_list)
#print('------')
resturant_info_list
=
[]
total_count_num
=
str
(
total_count_list
[
0
])
total_count_num
=
int
(
total_count_num
)
resturant_info
=
"[ 맛집 정보 ]"
resturant_info
=
""
resturant_string
=
"관련 음식점 정보: "
+
'
\n
'
#프린트 결과를 리턴받기 위한 함수
#from io import StringIO
...
...
@@ -140,14 +140,50 @@ def return_print(*message):
print
(
*
message
,
file
=
io
,
end
=
""
)
return
io
.
getvalue
()
print
(
resturant_info
)
# 봇 메세지 ㄱㄱ
for
i
in
range
(
0
,
10
):
#total_count_num가 너무 크면 인덱스 범위가 벗어나서 실행이 안됨, 임시로 10개까지만
resturant_info
=
[
place_name_list
[
i
]
+
" "
+
phone_list
[
i
]
+
" "
+
road_address_name_list
[
i
]
+
" "
+
place_url_list
[
i
]]
resturant_string
+=
str
(
resturant_info
)
+
"
\n
"
+
"
\n
"
for
i
in
range
(
0
,
10
):
#total_count_num가 너무 크면 인덱스 범위가 벗어나서 실행이 안됨, 임시로 5개까지만
resturant_info_print
=
print
([
place_name_list
[
i
]
+
" "
+
phone_list
[
i
]
+
" "
+
road_address_name_list
[
i
]
+
" "
+
place_url_list
[
i
]])
#resturant_info_list = [place_name_list[i] + " " +phone_list[i] + " " + road_address_name_list[i] + " " + place_url_list[i]]
#resturant_info += return_print(resturant_info_list)
# print(resturant_string)
#################################################################3
#텔레그램 관련 코드
token
=
"1721885449:AAHDGMbjSJfhXxML6nfSCpfiU7SghpL_vOE"
id
=
"1657858421"
bot
=
telegram
.
Bot
(
token
)
info_message
=
'''맛집 검색 기능: (#맛집)'''
########기능 리스트 ##############33
bot
.
sendMessage
(
chat_id
=
id
,
text
=
info_message
)
updater
=
Updater
(
token
=
token
,
use_context
=
True
)
dispatcher
=
updater
.
dispatcher
updater
.
start_polling
()
# 챗봇 응답
def
handler
(
update
,
context
):
user_text
=
update
.
message
.
text
# 사용자가 보낸 메세지를 user_text 변수에 저장합니다.
# 맛집 키워드 답장
if
(
"맛집"
in
user_text
):
bot
.
sendMessage
(
chat_id
=
id
,
text
=
resturant_string
)
elif
(
"고마워"
in
user_text
):
bot
.
send_message
(
chat_id
=
id
,
text
=
"웅 ㅎㅎ"
)
else
:
update
.
message
.
reply_text
(
"ㅎㅎ"
)
echo_handler
=
MessageHandler
(
Filters
.
text
,
handler
)
dispatcher
.
add_handler
(
echo_handler
)
...
...
Please
register
or
login
to post a comment