Skip to content

Commit

Permalink
UPDATED 02.13.2023
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbumgarner committed Feb 13, 2023
1 parent 575b0f5 commit 293121f
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 27 deletions.
2 changes: 1 addition & 1 deletion wordhoard/utilities/basic_soup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Date Completed: October 15, 2020
# Author: John Bumgarner
#
# Date Last Revised: February 04, 2023
# Date Last Revised: February 10, 2023
# Revised by: John Bumgarner
##################################################################################

Expand Down
115 changes: 115 additions & 0 deletions wordhoard/utilities/captcha_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/env python3

"""
This Python script is used to verify the HREF being queried is
protected by a captcha that requires human interaction to bypass.
"""
__author__ = 'John Bumgarner'
__date__ = 'December 07, 2021'
__status__ = 'Production'
__license__ = 'MIT'
__copyright__ = 'Copyright (C) 2021 John Bumgarner'

##################################################################################
# “AS-IS” Clause
#
# Except as represented in this agreement, all work produced by Developer is
# provided “AS IS”. Other than as provided in this agreement, Developer makes no
# other warranties, express or implied, and hereby disclaims all implied warranties,
# including any warranty of merchantability and warranty of fitness for a particular
# purpose.
##################################################################################

##################################################################################
# Date Completed: December 07, 2021
# Author: John Bumgarner
#
# Date Revised:
# Revised by:
##################################################################################

##################################################################################
# Python imports required for basic operations
##################################################################################
import logging

logger = logging.getLogger(__name__)


class CaptchaVerification(object):
"""
This Class is used to query a webpage to determine if it is protected by a captcha.
"""

def __init__(self, url, soup):
self._url = url
self._raw_soup = soup

def _check_div_tag(self):
"""
This function is designed to query for the existence
of specific tag known to be commonly related to a
captcha protected webpage.
:return: True or False
:rtype: boolean
"""
captcha_protected_div_tag = bool(self._raw_soup.find(name='div', attrs={'id': 'px-captcha'}))
if captcha_protected_div_tag is True:
logger.error(f'The {self._url} has captcha protection.')
return True
elif captcha_protected_div_tag is False:
return False

def _check_title_tag(self):
"""
This function is designed to query for the existence
of specific captcha related text contained in a title tag.
:return: True or False
:rtype: boolean
"""
title_tag = self._raw_soup.find(name='title')
if 'Are you a robot?' in title_tag.text:
logger.error(f'The {self._url} has captcha protection.')
return True
else:
return False

def _check_h2_tag(self):
"""
This function is designed to query for the existence
of specific captcha related text contained in an H2 tag.
:return: True or False
:rtype: boolean
"""
captcha_protected_h2_tag = bool(self._raw_soup.find(name='h2', attrs={'class': 'main__heading'}))
if captcha_protected_h2_tag is True:
captcha_protected_tag = self._raw_soup.find(name='h2', attrs={'class': 'main__heading'})
if "We've detected unusual activity from your computer network" in captcha_protected_tag.text:
return True
else:
return False

def captcha_protected_url(self):
"""
This function is designed to query specific elements, which
will determine if a webpage is protected by a captcha.
:return: True or False
:rtype: boolean
"""
div_tag_bool = self._check_div_tag()
if div_tag_bool is True:
return True
elif div_tag_bool is False:
title_tag_bool = self._check_title_tag()
if title_tag_bool is True:
return True
else:
h2_tag_bool = self._check_h2_tag()
if h2_tag_bool is True:
return True
else:
return False
2 changes: 1 addition & 1 deletion wordhoard/utilities/colorized_text.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

"""
This Python script provide colorized text in error messages thrown by WordHoard.
This Python script provide colorized text in the error messages thrown by WordHoard.
"""
__author__ = 'John Bumgarner'
__date__ = 'February 04, 2023'
Expand Down
4 changes: 3 additions & 1 deletion wordhoard/utilities/deep_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""
This Python script is used to translate a specific word from it source language,
such as Spanish into American English using the Deep translation service.
such as Spanish into American English using the Deep Translation service.
"""
__author__ = 'John Bumgarner'
__date__ = 'September 24, 2021'
Expand Down Expand Up @@ -266,6 +266,8 @@ def translate_word(self):
print(colorized_text(255, 0, 0, f'The language provided is not one of the supported languages '
f'for the Deep Translation service.'))
print(colorized_text(255, 0, 0, f'Requested language: {self._source_language}'))
print(colorized_text(255, 0, 0, f'Please review the languages supported by the Deep Translate service\n'
f'https://wordhoard.readthedocs.io/en/latest/translations/deepl_supported_translation_languages/'))
return None

def reverse_translate(self):
Expand Down
1 change: 0 additions & 1 deletion wordhoard/utilities/email_address_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#
##################################################################################


##################################################################################
# Python imports required for basic operations
##################################################################################
Expand Down
2 changes: 1 addition & 1 deletion wordhoard/utilities/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

"""
This Python script provides various Exceptions, which are used in the WordHoard Translation Classes.
This Python script provides various Exceptions Classes, which are used in the WordHoard Translation modules.
"""
__author__ = 'John Bumgarner'
__date__ = 'February 04, 2023'
Expand Down
8 changes: 5 additions & 3 deletions wordhoard/utilities/google_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""
This Python script is used to translate a specific word from it source language,
such as Spanish into American English using the Google translation service.
such as Spanish into American English using the Google Translation service.
"""
__author__ = 'John Bumgarner'
__date__ = 'September 24, 2021'
Expand Down Expand Up @@ -194,7 +194,7 @@ def _google_translate(self, original_language):
except RequestException as error:
"""
This exception is thrown when an ambiguous exception occurs during a connection to the
Google Translation service. Translator service.
Google Translation service.
"""
print(colorized_text(255, 0, 0, 'An ambiguous connection exception has occurred when contacting the'
'Google Translation service. Please check the WordHoard log file '
Expand Down Expand Up @@ -261,7 +261,7 @@ def _google_translate_reverse(self):
except RequestException as error:
"""
This exception is thrown when an ambiguous exception occurs during a connection to the
Google Translation service. Translator service.
Google Translation service.
"""
print(colorized_text(255, 0, 0, 'An ambiguous connection exception has occurred when contacting the'
'Google Translation service. Please check the WordHoard log file '
Expand All @@ -286,6 +286,8 @@ def translate_word(self):
print(colorized_text(255, 0, 0, f'The language provided is not one of the supported languages '
f'for the Google Translation service.'))
print(colorized_text(255, 0, 0, f'Requested language: {self._source_language}'))
print(colorized_text(255, 0, 0, f'Please review the languages supported by the Google Translation service\n'
f'https://wordhoard.readthedocs.io/en/latest/translations/google_supported_translation_languages/'))
return None

def reverse_translate(self):
Expand Down
25 changes: 12 additions & 13 deletions wordhoard/utilities/mymemory_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""
This Python script is used to translate a specific word from it source language,
such as Spanish into American English using the MyMemory translation service.
such as Spanish into American English using the MyMemory Translation service.
"""
__author__ = 'John Bumgarner'
__date__ = 'September 24, 2021'
Expand Down Expand Up @@ -116,7 +116,7 @@ def _mymemory_supported_languages(self):
service.
"""
logger.info(f'The language provided is not one of the supported languages of the MyMemory '
f'translation service.')
f'Translation service.')
logger.info(f'Requested language: {self._source_language}')
logger.error(''.join(traceback.format_tb(error.__traceback__)))

Expand Down Expand Up @@ -151,7 +151,7 @@ def _mymemory_translate(self, original_language):
try:
if validate_address(self._email_address) is False:
print(colorized_text(255, 0, 0,
'A valid email address is required to use the MyMemory translation '
'A valid email address is required to use the MyMemory Translation '
'service.'))
sys.exit(1)
elif validate_address(self._email_address) is True:
Expand Down Expand Up @@ -187,9 +187,9 @@ def _mymemory_translate(self, original_language):
not the validity of the address provided.
"""
print(colorized_text(255, 0, 0, 'The email address provided for authentication to the MyMemory '
'Translation MyMemory is invalid.'))
'Translation service is invalid.'))
logger.error('Invalid Email Address Error:')
logger.error('The email address provided for authentication to the MyMemory Translation MyMemory '
logger.error('The email address provided for authentication to the MyMemory Translation service '
'is invalid.')
logger.error(''.join(traceback.format_tb(error.__traceback__)))

Expand All @@ -198,7 +198,7 @@ def _mymemory_translate(self, original_language):
This exception is thrown if the provided text exceed the length limit of the MyMemory Translator service.
"""
logger.error(f'The text length for the word: {self._str_to_translate} exceed the length limit of '
f'MyMemory translation service.')
f'MyMemory Translation service.')
logger.error(''.join(traceback.format_tb(error.__traceback__)))

except TooManyRequestsException as error:
Expand Down Expand Up @@ -235,7 +235,7 @@ def _mymemory_translate_reverse(self):
try:
if validate_address(self._email_address) is False:
print(colorized_text(255, 0, 0,
'A valid email address is required to use the MyMemory translation '
'A valid email address is required to use the MyMemory Translation '
'service.'))
sys.exit(1)
elif validate_address(self._email_address) is True:
Expand Down Expand Up @@ -271,9 +271,9 @@ def _mymemory_translate_reverse(self):
not the validity of the address provided.
"""
print(colorized_text(255, 0, 0, 'The email address provided for authentication to the MyMemory '
'Translation MyMemory is invalid.'))
'Translation is invalid.'))
logger.error('Invalid Email Address Error:')
logger.error('The email address provided for authentication to the MyMemory Translation MyMemory '
logger.error('The email address provided for authentication to the MyMemory Translation '
'is invalid.')
logger.error(''.join(traceback.format_tb(error.__traceback__)))
sys.exit(1)
Expand Down Expand Up @@ -307,7 +307,7 @@ def _mymemory_translate_reverse(self):
'for additional information.'))
logger.error('Connection Exception:')
logger.error('An ambiguous connection exception has occurred when communicating with the '
'MyMemoryTranslation service.')
'MyMemory Translation service.')
logger.error(''.join(traceback.format_tb(error.__traceback__)))

def translate_word(self):
Expand All @@ -324,9 +324,8 @@ def translate_word(self):
print(colorized_text(255, 0, 0, f'The language provided is not one of the supported languages '
f'for the MyMemory Translation service.'))
print(colorized_text(255, 0, 0, f'Requested language: {self._source_language}'))
print(colorized_text(255, 0, 0, f'Please review Mymemory'
f'https://wordhoard.readthedocs.io/en/latest/supported_languages'
f'for the Mymemory'))
print(colorized_text(255, 0, 0, f'Please review the languages supported by the MyMemory Translate service\n'
f'https://wordhoard.readthedocs.io/en/latest/translations/mymemory_supported_translation_languages/'))

return None

Expand Down
10 changes: 5 additions & 5 deletions wordhoard/utilities/translator_languages.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python3

"""
This Python script provides the supported languages for the translation services used
by WordHoard.
This Python script provides the supported languages for the translation modules
embedded into WordHoard.
"""
__author__ = 'John Bumgarner'
__date__ = 'February 12, 2023'
Expand Down Expand Up @@ -34,7 +34,7 @@ class Languages:
@staticmethod
def deep_supported_languages():
"""
This function returns the supported languages for the Deep translation service.
This function returns the supported languages for the Deep Translation service.
:return: languages
:rtype: string
Expand Down Expand Up @@ -75,7 +75,7 @@ def deep_supported_languages():
@staticmethod
def google_supported_languages():
"""
This function returns the supported languages for the Google Translator service.
This function returns the supported languages for the Google Translation service.
:return: languages
:rtype: string
Expand Down Expand Up @@ -221,7 +221,7 @@ def google_supported_languages():
@staticmethod
def mymemory_supported_languages():
"""
This function returns the supported languages for the MyMemory Translator services.
This function returns the supported languages for the MyMemory Translation service.
:return: languages
:rtype: string
Expand Down
3 changes: 2 additions & 1 deletion wordhoard/utilities/word_verification.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3

"""
This Python script is to validate the syntax of words to query.
This Python script is designed to validate the syntax of word in a query
meets a format requirement.
"""
__author__ = 'John Bumgarner'
__date__ = 'October 15, 2020'
Expand Down

0 comments on commit 293121f

Please sign in to comment.