<commit_before>#!/usr/bin/env python

from __future__ import print_function

from collections import Counter
from json import dumps
from HTMLParser import HTMLParser
import csv
import re
import time

from common import Tool


class GatherLinks(HTMLParser):
    re_url = re.compile(r'^/importer/(?P<num>\d+)$')

    def __init__(self, *args, **kwargs):
        self.import_ids = set()
        HTMLParser.__init__(self, *args, **kwargs)

    def handle_starttag(self, tag, attrs):
        if tag == 'a':
            for attr, value in attrs:
                if attr == 'href':
                    m = self.re_url.match(value)
                    if m:
                        self.import_ids.add(int(m.group("num")))

    def get_urls(self):
        return ["/importer/%d.json" % i for i in sorted(self.import_ids)]


class GatherImportIssues(Tool):
    """Gather import issues into CSVs."""
    logger_name = 'tools.gather_import_issues'
    parser_options = ['api', 'data']

    def run(self, by_url_csv, by_issue_csv, *args, **kwargs):
        issue_rows = self.download_issues()
        issue_counts = Counter()

        # Write by-url CSV and count issues
        by_url_writer = csv.writer(by_url_csv)
        by_url_writer.writerow([
            "MDN Slug", "Import URL", "Issue Slug", "Source Start",
            "Source End", "Params"])
        for row in issue_rows:
            err = row[4]
            issue_counts[err] += 1<commit_msg>bug 1154349 - Counts in gather_import_issues.py<commit_after>#!/usr/bin/env python

from __future__ import print_function

from collections import Counter
from json import dumps
from HTMLParser import HTMLParser
import csv
import re
import time

from common import Tool


class GatherLinks(HTMLParser):
    re_url = re.compile(r'^/importer/(?P<num>\d+)$')

    def __init__(self, *args, **kwargs):
        self.import_ids = set()
        HTMLParser.__init__(self, *args, **kwargs)

    def handle_starttag(self, tag, attrs):
        if tag == 'a':
            for attr, value in attrs:
                if attr == 'href':
                    m = self.re_url.match(value)
                    if m:
                        self.import_ids.add(int(m.group("num")))

    def get_urls(self):
        return ["/importer/%d.json" % i for i in sorted(self.import_ids)]


class GatherImportIssues(Tool):
    """Gather import issues into CSVs."""
    logger_name = 'tools.gather_import_issues'
    parser_options = ['api', 'data']

    def run(self, by_url_csv, by_issue_csv, *args, **kwargs):
        issue_rows = self.download_issues()
        issue_counts = Counter()

        # Write by-url CSV and count issues
        by_url_writer = csv.writer(by_url_csv)
        by_url_writer.writerow([
            "MDN Slug", "Import URL", "Issue Slug", "Source Start",
            "Source End", "Params"])
        for row in issue_rows:
            err = row[2]
            issue_counts[err] += 1
{'fraction_non_alphanumeric': 0.11825017088174983, 'fraction_numerical': 0.0037593984962406013, 'mean_word_length': 2.4435294117647057, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6789663', 'n_tokens_mistral': 938, 'n_tokens_neox': 897, 'n_words': 243}