def db_insert_website(domain): """ This method inserts a website into the websites table of the database. :param domain: The domain of the website to insert in the database. """ website = Website( domain=domain, last_crawled_on=datetime.now().strftime("%Y-%m-%d %H:%M:%S")) session = db_session() session.add(website) session.commit() session.close()
def db_insert_bookmark(url, name, user): url = remove_scheme(url) bookmark = Bookmark(url=url, name=name, user=user) session = db_session() try: session.add(bookmark) session.commit() except Exception as e: if "url" in e.args[0]: raise BookmarkUrlTaken elif "name" in e.args[0]: raise BookmarkNameTaken finally: session.close()
def db_insert_action(action, url): """ This method inserts an action performed by the user into the history table of the database. :param action: A string indicating the action performed by the user. :param url: The url of the web page related to the action performed by the user. """ url = remove_scheme(url) session = db_session() history = History(user="******", action=action, url=url, timestamp=datetime.now().strftime("%Y-%m-%d %H:%M:%S")) session.add(history) session.commit() session.close()
def db_insert_functionality_link(page_url, name, link_url, score): page_url = remove_scheme(page_url) session = db_session() functionality = Functionality(page_url=page_url, type="link", name=name, link_url=link_url, score=score) try: session.add(functionality) session.commit() except Exception: # Exception if link already present. session.rollback() finally: session.close()
def db_insert_page_link(page_url, link_url, link_text, x_position, y_position, in_list, in_nav): page_url = remove_scheme(page_url) link_url = remove_scheme(link_url) page_link = PageLink(page_url=page_url, link_url=link_url, link_text=link_text, x_position=x_position, y_position=y_position, in_list=in_list, in_nav=in_nav) session = db_session() session.add(page_link) session.commit() session.close()
def db_insert_page(url, simple_html): """ This method inserts a web page in the pages table of the database. """ url = remove_scheme(url) page = Page(url=url, simple_html=simple_html, last_visit=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), parsed_html="In progress.") session = db_session() try: session.add(page) session.commit() except IntegrityError: session.rollback() finally: session.close()
def db_insert_form(page_url, form_num, method, action, input_num, input_name, input_text): page_url = remove_scheme(page_url) form = Form(page_url=page_url, form_num=form_num, method=method, action=action, input_num=input_num, input_name=input_name, input_text=input_text) session = db_session() try: session.add(form) session.commit() except Exception: session.rollback() finally: session.close()
def db_insert_text_link(page_url, link_num, link): """ This method inserts a link contained in the main text of a web page into the page_links table of the database. :param page_url: A string containing the URL of the web page containing the link. :param link_num: A number representing the index of the link to insert between all the other links of the text. :param link: A tuple (position, link_text, link_url) containing info about the link. :return: None. """ page_url = remove_scheme(page_url) text_link = TextLink(page_url=page_url, link_num=link_num, position=link[0], link_text=link[1], link_url=link[2]) session = db_session() session.add(text_link) session.commit() session.close()