<commit_before>#!/usr/bin/env python
"""
    <name>
        check_list.py

    <Description>
        Obtains a random word from /usr/share/words and checks
        if there is a list of that. 

    <Usage>
        from check_list import check_random_list, LOLException
        try:
            check_random_list()
        Except LOLException as e:
            print("{}".format(e))
        else:
            print("No new list-less object for LOL")
""" 
import wikipedia
import linereader
import random

DICT = "../dict.txt"
WC_DICT = 48915

class LOLException(Exception):
    pass

def check_random_list():

    # get a random word from our magical wikipedia page 
    randfile = linereader.copen(DICT)
    random_word = randfile.getline(random.randint(1, WC_DICT))

    try:
        query = "List of {}".format(random_word)
        page = wikipedia.page(query)
        result_word = page.title.lstrip("List of")
        if result_word != random_word:
            raise LOLException(random_word)
    except wikipedia.exceptions.PageError:
        raise LOLException(random_word)
    
    return random_word

if __name__ == "__main__":
    try:
        random_word = check_random_list()
    except LOLException as e:
        print("There is not a list of {}".format(e))
    else:
        print("There is a list of {}".format(random_word))

<commit_msg>FIX: Addresses comments + pep8 run<commit_after>"""
    <name>
        check_list.py

    <Description>
        Obtains a random word from /usr/share/words and checks
        if there is a list of that.

    <Usage>
        from check_list import check_random_list, LOLException
        try:
            check_random_list()
        except LOLException as e:
            print("{}".format(e))
        else:
            print("No new list-less object for LOL")
"""
import wikipedia
import linereader
import random

DICT = "../dict.txt"
WC_DICT = 48915


class LOLException(Exception):
    """
        <Name>
            LOLException

        <Description>
            This exception is raised when a wikipedia page does not contain a
            list of such word. The List-less Object is contained in the message
    """
    pass


def check_random_list():
    """
        <Name>
            check_random_list()

        <Description>
            Randomly picks a word from a dictionary and tries to fetch the
            wikipedia article of a list for it. If there is a list of this
            word, the word is returned. If there isn't a LOLException is
            raised.

        <Raises>
            LOLException(word): if there isn't a list of this word in wikipedia

        <Returns>
            word: the word that *does* contain a list
    """

    # get a random word from our magical wikipedia page
    randfile = linereader.copen(DICT)
    random_word = randfile.getline(random.randint(1, WC_DICT))

    query = "List of {}".format(random_word)
    try:
        page = wikipedia.page(query)
    except wikipedia.exceptions.PageError:
        raise LOLException(random_word)

    result_word = page.title.lstrip("List of")
    if result_word != random_word:
        raise LOLException(random_word)

    return random_word

if __name__ == "__main__":
    try:
        random_word = check_random_list()
    except LOLException as e:
        print("There is not a list of {}".format(e))
    else:
        print("There is a list of {}".format(random_word))

{'fraction_non_alphanumeric': 0.08745247148288973, 'fraction_numerical': 0.0038022813688212928, 'mean_word_length': 2.2758620689655173, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 15, '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': '2924432', 'n_tokens_mistral': 1037, 'n_tokens_neox': 978, 'n_words': 320}