def get_calendar(self, dump): today = datetime.today() soup = WebCrawler().get_soup( "http://www.gsm.hs.kr/xboard/board.php?tbnum=4") try: info = soup.select("#xb_fm_list > div.calendar > ul > li > dl") result = "```" for i in info: if not i.find("dd") == None: text = i.text.replace("\n", "") result += "%6s -%s\n" % (text.split("-")[0], text.split("-")[1]) for i in text.split("-")[2:]: result += "%7s -%s\n" % ("", i) result += "```" return result except AttributeError: print("[오류] GSM Bot이 학사일정을 불러올 수 없습니다.") return "%s년 %s월 학사일정을 불러올 수 없습니다." % (today.year, today.month)
def get_hungry(self, dump): today = self.get_nextDay() nextMeal = self.get_nextMeal(today) item = ["아침", "점심", "저녁"] soup = WebCrawler().get_soup( "http://www.gsm.hs.kr/xboard/board.php?tbnum=8&sYear=%s&sMonth=%s" % (today.year, today.month)) try: info = soup.select( "#xb_fm_list > div.calendar > ul > li > div > div.slider_food_list.slider_food%s.cycle-slideshow" % today.day) menuList = (info[0].find( "div", { "data-cycle-pager-template": "<a href=#none; class=today_food_on%s title=%s></a>" % (nextMeal % 3 + 1, item[nextMeal % 3]) }).find("span", "content").text).split("\n") p = re.compile("(?!에너지)[가-힣]+") # 영양성분 문장을 제외하기 위한 정규표현식 result = "" for i in menuList: if p.match(i.split()[0]): result += ("- " + i.split()[0] + "\n") # result의 길이가 0이면 if not len(result): raise Exception return result except: print("[오류] GSM Bot이 식단표를 받아올 수 없습니다.") return "%s 급식을 불러올 수 없습니다." % item[nextMeal % 3]