def news(): type = request.args.get("type", "top", type=str) html_soup = get_html() if type == "all": news_url = news_page_link(html_soup) html_soup = get_html(news_url) type_function_map = { "all": get_all_news, "top": get_top_news, "link": news_page_link, } data = type_function_map[type](html_soup) return json.dumps(data)
def get_downloadable(): """ Returns -> Dict{ 'left': Dict { 'link': Link of downloadable item 'caption': Short description of item } } """ html_soup = get_html() # Get the downloadable item in left side left_div = html_soup.find("div#leftnoav", first=True) left_div_a_tag = left_div.find("p", first=True).find("a", first=True) left_title = left_div_a_tag.text link = left_div_a_tag.attrs.get("href") left_link = f"{html_soup.url}/{link.strip()}" # TODO Get the downloadable item in Right side downloadables = { "left": { "link": left_link, "caption": left_title }, # 'right': {'link': left_link, 'title': title}, } return downloadables
def get_footer(): """ Returns -> Dict { 'privacy_policy': link to site's privacy policy 'disclaimer': link to site's disclaimer 'youtube': trinity's youtube channel 'twitter': trinity's twitter handle 'facebook': trinity's facebook page } """ html_soup = get_html() footer_div = html_soup.find("#footer", first=True) legal_div = footer_div.find("div", first=True) a_tags = legal_div.find("a") privacy_policy = a_tags[0].attrs.get("href") disclaimer = a_tags[1].attrs.get("href") privacy_policy_link = html_soup.url + "/" + privacy_policy disclaimer_link = html_soup.url + "/" + disclaimer # TODO For now social media links are hardcoded :) facebook = "https://www.facebook.com/" trinity_fb_id = "Trinity-International-HSSCollege-123877371368846/?fref=ts" youtube_link = "https://www.youtube.com/channel/UCI9QxocOF5Dy5_skkOYIGiA" twitter_link = "https://twitter.com/TrinityHSSchool" footer_items = { "privacy_policy": privacy_policy_link, "disclaimer": disclaimer_link, "youtube": youtube_link, "twitter": twitter_link, "facebook": facebook + trinity_fb_id, } return footer_items
def get_login_captcha(): """ Returns -> [str] math captcha in login. """ html_soup = get_html() login_captcha_xpath = ( "/html/body/div/div[2]/div[2]/div[3]/div[2]/form/div[4]/div[1]") captcha_str = html_soup.xpath(login_captcha_xpath, first=True).text return captcha_str
def footer(): html_soup = get_html() data = get_footer() return json.dumps(data)
def downloadable(): html_soup = get_html() data = get_downloadable() return json.dumps(data)
def navigation(): type = request.args.get("type", "side", type=str) html_soup = get_html() type_function_map = {"side": get_side_nav_menu, "main": get_main_nav_menu} data = type_function_map[type](html_soup) return json.dumps(data)
def event(): type = request.args.get("type", "top", type=str) type_function_map = {"top": get_top_event, "link": event_page_link} html_soup = get_html() data = type_function_map[type](html_soup) return json.dumps(data)