<commit_before>import time
from urllib.parse import urljoin
from bs4 import BeautifulSoup
from crawler.page_request import PageRequest
from crawler.page_report import PageReport
from crawler.report_builder import ReportBuilder


class Crawler(object):
    '''
    The main crawler object that the user interacts with
    '''
    crawled_urls = []
    page_reports = []

    def __init__(self, root_url, start_url=None, crawl_limit=5):
        self.root_url = root_url
        if start_url:
            self.start_url = start_url
        else:
            self.start_url = root_url
        self.crawl_limit = crawl_limit

    def start_crawl(self):
        '''
        Begins crawling the given site at the initialized start_url
        '''
        self.url_queue = [self.start_url]
        while self.url_queue and len(self.crawled_urls) < self.crawl_limit:
            current_url = self.url_queue.pop(0)

            if current_url in self.crawled_urls:
                continue
            if self.is_outbound_url(current_url):
                print("Skipping outbound url ", current_url)
                continue

            try:
                response = self.get_response(current_url)
            except:
                # TODO: Put malformed urls in page report
                print('Skipping malformed URL - ', current_url)
                continue

            page_report = PageReport(
                url=current_url,
                root_url=self.root_url,
                status_code=response.status_code,
                redirects=response.history,
                page_links=self.get_absolute_page_links(current_url, response))

            self.url_queue += page_report.page_links
            self.page_reports.append(page_report)
            self.crawled_urls.append(current_url)
            self.sleep()<commit_msg>Adding debug strings while crawling to give user some feedback on the progress of their crawl<commit_after>import time
from urllib.parse import urljoin
from bs4 import BeautifulSoup
from crawler.page_request import PageRequest
from crawler.page_report import PageReport
from crawler.report_builder import ReportBuilder


class Crawler(object):
    '''
    The main crawler object that the user interacts with
    '''
    crawled_urls = []
    page_reports = []

    def __init__(self, root_url, start_url=None, crawl_limit=5):
        self.root_url = root_url
        if start_url:
            self.start_url = start_url
        else:
            self.start_url = root_url
        self.crawl_limit = crawl_limit

    def start_crawl(self):
        '''
        Begins crawling the given site at the initialized start_url
        '''
        self.url_queue = [self.start_url]
        while self.url_queue and len(self.crawled_urls) < self.crawl_limit:
            current_url = self.url_queue.pop(0)

            if current_url in self.crawled_urls:
                continue
            if self.is_outbound_url(current_url):
                print("Skipping outbound url ", current_url)
                continue

            try:
                response = self.get_response(current_url)
            except:
                # TODO: Put malformed urls in page report
                print('Skipping malformed URL - ', current_url)
                continue

            page_report = PageReport(
                url=current_url,
                root_url=self.root_url,
                status_code=response.status_code,
                redirects=response.history,
                page_links=self.get_absolute_page_links(current_url, response))

            self.url_queue += page_report.page_links
            self.page_reports.append(page_report)
            print(page_report)
            self.crawled_urls.append(current_url)
            self.sleep()
{'fraction_non_alphanumeric': 0.06661379857256146, 'fraction_numerical': 0.0015860428231562252, 'mean_word_length': 2.0442477876106193, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1258422', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1033, 'n_words': 239}