<commit_before>#!/usr/bin/env python3
from subprocess import check_output


def __query(domain, limit=100):
    """Using the shell script to query pdns.cert.at is a hack, but python raises an error every time using subprocess
    functions to call whois. So this hack is avoiding calling whois directly. Ugly, but works.

    :param domain: The domain pdns is queried with.
    :type domain: str
    :param limit: Maximum number of results
    :type limit: int
    :returns: str -- Console output from whois call.
    :rtype: str
    """
    s = check_output(['./whois.sh', '--limit {} {}'.format(limit, domain)], universal_newlines=True)
    return s


def __process_results(results):
    """Processes the result from __query to get valid json from every entry.

    :param results: Results from __query
    :type results: str
    :returns: python list of dictionaries containing the relevant results.
    :rtype: list
    """
    result_list = []

    # Splts the result and cuts first and last dataset which are comments
    split = results.split(sep='\n\n')[1:-1]

    for entry in split:
        entry_dict = {}
        for value in entry.split('\n'):
            if len(value) < 1:
                continue
            (desc, val) = value.split(': ')
            entry_dict[desc.replace('-', '')] = val.strip(' ')
        result_list.append(entry_dict)
    return result_list


def query(domain: str, limit: int=100):
    """Queries and returns a python dict with results.

    :param domain: domain that should be queried
    :type domain: str
    :param limit: number of entries to return
    :type limit: int
    :returns: query results
    :rtype: list
    """
    return __process_results(__query(domain, limit))
<commit_msg>Fixes #362: empty result set in cert.at pdns analyzer and correct path for whois.sh<commit_after>#!/usr/bin/env python3
import os
from subprocess import check_output


def __query(domain, limit=100):
    """Using the shell script to query pdns.cert.at is a hack, but python raises an error every time using subprocess
    functions to call whois. So this hack is avoiding calling whois directly. Ugly, but works.

    :param domain: The domain pdns is queried with.
    :type domain: str
    :param limit: Maximum number of results
    :type limit: int
    :returns: str -- Console output from whois call.
    :rtype: str
    """
    s = check_output(['{}/whois.sh'.format(os.getcwd()), '--limit {} {}'.format(limit, domain)], universal_newlines=True)
    return s


def __process_results(results):
    """Processes the result from __query to get valid json from every entry.

    :param results: Results from __query
    :type results: str
    :returns: python list of dictionaries containing the relevant results.
    :rtype: list
    """
    if 'no match' in results and 'returning 0 elements' in results:
        return []

    result_list = []

    # Splts the result and cuts first and last dataset which are comments
    split = results.split(sep='\n\n')[1:-1]

    for entry in split:
        entry_dict = {}
        for value in entry.split('\n'):
            if len(value) < 1:
                continue
            (desc, val) = value.split(': ')
            entry_dict[desc.replace('-', '')] = val.strip(' ')
        result_list.append(entry_dict)
    return result_list


def query(domain: str, limit: int=100):
    """Queries and returns a python dict with results.

    :param domain: domain that should be queried
    :type domain: str
    :param limit: number of entries to return
    :type limit: int
    :returns: query results
    :rtype: list
    """
    return __process_results(__query(domain, limit))

{'fraction_non_alphanumeric': 0.10273224043715846, 'fraction_numerical': 0.006557377049180328, 'mean_word_length': 2.8658922914466736, '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': '2878849', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1039, 'n_words': 407}