src/finite_dino_bot.py
def retrieve_definition(query):
        """Retrieve and extract first set of word definitions.

        Returns
        -------
        dict
            defintion, query_url, word_class, word
        """
        print('Looking up "{}"...'.format(query))

        query_url = FiniteDinoBot.DEFINE_URL + query.replace(' ', '_')

        url_request = urllib.request.Request(
            query_url,
            headers={'User-Agent': (
                'Mozilla/5.0 (Linux x86_64)'
                )}
            )

        try:
            with urllib.request.urlopen(url_request) as response:
                html = response.read()
        except urllib.error.HTTPError as error:
            print(error)
            print("Query not found.")
            return None

        soup = BeautifulSoup(html, 'html.parser')

        try:
            raw_definition = soup.find(
                'span',
                attrs={'id': [
                    'Noun', 'Pronoun', 'Verb', 'Adjective', 'Adverb',
                    'Conjunction', 'Preposition', 'Interjection'
                    ]},
                )
            print("Definition found.")
            return {
                'definition': str(raw_definition.find_next('ol')),
                'query_url': query_url,
                'word_class': raw_definition.get_text(),
                'word': str(raw_definition.find_next('p')),
                }
        except AttributeError as error:
            print('Error: No valid definition detected.')
            return None
Retrieve and extract first set of word definitions.

        Returns
        -------
        dict
            defintion, query_url, word_class, word
        
Retrieve and extract first set of word definitions.
Returns


Retrieve and extract first set of word definitions . Returns
def retrieve_definition(query):
        print('Looking up "{}"...'.format(query))
        query_url = FiniteDinoBot.DEFINE_URL + query.replace(' ', '_')
        url_request = urllib.request.Request(
            query_url,
            headers={'User-Agent': (
                'Mozilla/5.0 (Linux x86_64)'
                )}
            )
        try:
            with urllib.request.urlopen(url_request) as response:
                html = response.read()
        except urllib.error.HTTPError as error:
            print(error)
            print("Query not found.")
            return None
        soup = BeautifulSoup(html, 'html.parser')
        try:
            raw_definition = soup.find(
                'span',
                attrs={'id': [
                    'Noun', 'Pronoun', 'Verb', 'Adjective', 'Adverb',
                    'Conjunction', 'Preposition', 'Interjection'
                    ]},
                )
            print("Definition found.")
            return {
                'definition': str(raw_definition.find_next('ol')),
                'query_url': query_url,
                'word_class': raw_definition.get_text(),
                'word': str(raw_definition.find_next('p')),
                }
        except AttributeError as error:
            print('Error: No valid definition detected.')
            return None
def retrieve_definition ( query ) : print ( 'Looking up "{}"...' . format ( query ) ) query_url = FiniteDinoBot . DEFINE_URL + query . replace ( ' ' , '_' ) url_request = urllib . request . Request ( query_url , headers = { 'User-Agent' : ( 'Mozilla/5.0 (Linux x86_64)' ) } ) try : with urllib . request . urlopen ( url_request ) as response : html = response . read ( ) except urllib . error . HTTPError as error : print ( error ) print ( "Query not found." ) return None soup = BeautifulSoup ( html , 'html.parser' ) try : raw_definition = soup . find ( 'span' , attrs = { 'id' : [ 'Noun' , 'Pronoun' , 'Verb' , 'Adjective' , 'Adverb' , 'Conjunction' , 'Preposition' , 'Interjection' ] } , ) print ( "Definition found." ) return { 'definition' : str ( raw_definition . find_next ( 'ol' ) ) , 'query_url' : query_url , 'word_class' : raw_definition . get_text ( ) , 'word' : str ( raw_definition . find_next ( 'p' ) ) , } except AttributeError as error : print ( 'Error: No valid definition detected.' ) return None
Retrieve and extract first set of word definitions.
Retrieve and extract first set of word definitions .
"""Retrieve and extract first set of word definitions.

        Returns
        -------
        dict
            defintion, query_url, word_class, word
        """
query