def is_the_link_already_searched_for(starting_url): with session_scope() as session: list_of_tuple_urls = session.query(Url).with_entities( Url.url_string).all() urls = list(map(lambda url: url[0], list_of_tuple_urls)) if starting_url in urls: return urls[-1] return starting_url
def create_plot(choose_option, time_chosen): with session_scope() as session: domain_names_raw = session.query(Domain) \ .filter(Domain.visited_at >= time_chosen) \ .with_entities(Domain.domain_name) \ .all() domain_names = list(map(lambda x: x[0], domain_names_raw)) unique_domain_names = list(set(domain_names)) count_of_domains = ['Unique domains'] plt.rcdefaults() fig, ax = plt.subplots() y_pos = [len(unique_domain_names)] width = [len(unique_domain_names)] error = [len(unique_domain_names)] ax.barh(y_pos, width, xerr=error, align='center') ax.set_yticks(y_pos) ax.set_yticklabels(count_of_domains) ax.invert_yaxis() # labels read top-to-bottom ax.set_xlabel('User statistics') ax.set_title(f'Domains found in the last {choose_option}') plt.show()
def is_url_visited(url_string): with session_scope() as session: does_url_exist = bool( session.query(Url).filter(Url.url_string == url_string).first()) return does_url_exist
def get_labels(): with session_scope() as session: labels_raw = session.query(Server).group_by( Server.server_name).with_entities(Server.server_name).all() labels = list(map(lambda x: x[0], labels_raw)) return labels
def add_entry_to_db(entry): with session_scope() as session: session.add(entry)