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 13:42:01 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
62728adb55b89d1ee4a8d9b986e43173b544e668
62728adb
1 parent
c9a2af45
search_restaurant1 with telegram
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
13 deletions
search_restaurant1.py
search_restaurant1.py
View file @
62728ad
...
...
@@ -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
...
...
@@ -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,52 @@ 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
)
react_weather
=
'''오늘 날씨 봐봐'''
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