<commit_before>"""
Author: <NAME>

Usage: (in adjacent script) from TrialsDownloader import x

This script contains a class which, given specified search criteria,
formats said criteria into an url utilized to download clinical trial
details from clinicaltrials.gov. in a .zip file.

The script then extracts the .xml files within and stores the in the
adjacent /downloads/ folder.
"""

import requests
import os
import zipfile
import errno


BASE_PATH = os.path.dirname(
    os.path.abspath(__file__)
)

DOWNLOAD_PATH = BASE_PATH + '/downloads/'
SEARCH_PARAMETERS_FILE = BASE_PATH + '/params.txt'


class TrialsDownloader(object):
    """
    This collects research from clinicaltrials.gov as specified
    by the criteria designated within the adjacent text file
    params.txt. For instructions on how to format this file,
    please see README.md
    """
    search_criteria = []
    relative_download_dirs = []

    def __init__(self, terms=None):
        print('> Gathering search criteria...')

        if terms is None:
            self.get_search_criteria()
        else:
            term_list = terms.split('_')
            self.search_criteria.extend(term_list)

        self.make_sure_path_exists(DOWNLOAD_PATH.strip('/'))
        for criteria in self.search_criteria:
            self.download_research(criteria)

    def get_search_criteria(self):<commit_msg>Updated docstrings.<commit_after>"""
Author: <NAME>

Usage: (in adjacent script) from TrialsDownloader import x

This script contains a class which, given specified search criteria,
formats said criteria into an url utilized to download clinical trial
details from clinicaltrials.gov. in a .zip file.

The script then extracts the .xml files within and stores the in the
adjacent /downloads/ folder.
"""

import requests
import os
import zipfile
import errno


BASE_PATH = os.path.dirname(
    os.path.abspath(__file__)
)

DOWNLOAD_PATH = BASE_PATH + '/downloads/'
SEARCH_PARAMETERS_FILE = BASE_PATH + '/params.txt'


class TrialsDownloader(object):
    """
    This collects research from clinicaltrials.gov as specified
    by the criteria designated within the adjacent text file
    params.txt. For instructions on how to format this file,
    please see README.md.

    If terms is specified upon initialization,
    usage of params.txt is overridden and the passed
    terms are utilized.
    """
    search_criteria = []
    relative_download_dirs = []

    def __init__(self, terms=None):
        print('> Gathering search criteria...')

        if terms is None:
            self.get_search_criteria()
        else:
            term_list = terms.split('_')
            self.search_criteria.extend(term_list)

        self.make_sure_path_exists(DOWNLOAD_PATH.strip('/'))
        for criteria in self.search_criteria:
            self.download_research(criteria)

    def get_search_criteria(self):
{'fraction_non_alphanumeric': 0.07887421820708826, 'fraction_numerical': 0.0, 'mean_word_length': 3.2842261904761907, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7205385', 'n_tokens_mistral': 822, 'n_tokens_neox': 795, 'n_words': 273}