파이썬으로 영화 상영시간표 알려주는 텔레그램 봇을 만들고 있습니다. 표를 보여줄려면 어떤 방법을 써야하는지 몰라서 질문 남깁니다.

조회수 605회
//import telegram
from telegram.ext import Updater
from telegram.ext import MessageHandler, Filters
from bs4 import BeautifulSoup
import urllib.request as req



######영등포 cgv 크롤링 관련 함수#####
code = req.urlopen("http://www.cgv.co.kr/common/showtimes/iframeTheater.aspx?areacode=01&theatercode=0059&date=20200315")
soup = BeautifulSoup(code, "html.parser")
movies = soup.select('body > div > div.sect-showtimes > ul > li')
for movie in movies:
     title = movie.select_one('div > div.info-movie > a > strong').get_text().strip()
timetables = movie.select('div > div.type-hall > div.info-timetable > ul > li')

def Movie_title_crawling():
    output_result = ""
    for movie in movies:
        title = movie.select_one('div > div.info-movie > a > strong').get_text().strip()
        output_result += title + "\n"
    return output_result

def Movie_timetable_crawling():
    tuples =[]
    for timetable in timetables:
        time = timetable.select_one('em').get_text()
        seat = timetable.select_one('span').get_text()
        tuple = (time,seat)
        tuples.append(tuple)
        for movie in movies:
            output_result = ""
            title = movie.select_one('div > div.info-movie > a > strong').get_text().strip()
            timetable = tuples
            output_result += title + timetable
    return output_result
############################

#####텔레그램 관련 코드######
token = ""
id = ""
bot = telegram.Bot(token)
info_message = '''- 오늘 상영하는 영화 : "영화" or "ㅇㅎ" 입력
- 오늘 상영하는 영화 상영시간표 : "상영" or "ㅅㅇ" 입력 '''
bot.sendMessage(chat_id = id, text=info_message)

# updater
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 (user_text == "영화") or (user_text == "ㅇㅎ"):
        Movie = Movie_title_crawling()
        bot.send_message(chat_id = id , text="오늘 상영하는 영화\n{}".format(Movie))
        bot.sendMessage(chat_id=id, text=info_message)
    #오늘의 상영시간표 알려줌
    elif (user_text == "상영") or (user_text == "ㅅㅇ"):
        Timetable=Movie_timetable_crawling()
        bot.send_message(chat_id = id, text="{}".format(Timetable))
        bot.sendMessage(chat_id=id, text=info_message)
echo_handler = MessageHandler(Filters.text, handler)
dispatcher.add_handler(echo_handler)

이 코드를 실행하면 영화는 잘 나오는데 상영시간표도 영화 제목 나오는 것처럼 하고 싶은데 에러가 뜨고 실행이 안됩니다. TypeError: can only concatenate str (not "list") to str 이런 에러가 뜹니다. 제 생각에는 def Movie_timetable_crawling() 함수를 바꿔야 할 것 같은데 어떻게 바꿔야 하는지 잘 모르겠습니다. 도와주시면 감사합니다.

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)