From dc328362de6f871cb94ed13c5d6706066f89420b Mon Sep 17 00:00:00 2001 From: Joe Mazzone Date: Thu, 13 Jul 2023 00:16:39 -0400 Subject: [PATCH] Update htmlcssgrade.py Add bug fix for logging warnings failing test cases and also added the two feature requests. --- htmlcssgrade.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/htmlcssgrade.py b/htmlcssgrade.py index 4d0a357..9653f49 100644 --- a/htmlcssgrade.py +++ b/htmlcssgrade.py @@ -1,12 +1,13 @@ ####################### # HTML/CSS Grade -# Version 1.0.2 +# Version 1.1.0 # Created by Joe Mazzone # Documentation: https://github.com/MrMazzone/HTML-CSS-Grade ####################### from bs4 import BeautifulSoup import cssutils +import logging class HTML_Check: """ @@ -60,6 +61,18 @@ def check_num_element_used(self, element, number): def get_num_element_used(self, element): """Gets the number of times ___ element is used.""" return (len(self.html_obj.find_all(element))) + + def get_element_content(self, element): + """Gets ___ element's content.""" + for line in self.html_obj.find_all(element): + return str(line.contents) + + def get_all_element_content(self, element): + """Gets all ___ element's content in a list.""" + all_content = [] + for line in self.html_obj.find_all(element): + all_content += line.contents + return all_content def check_element_content(self, element, content): """Does ___ element contain ___ content?""" @@ -75,6 +88,18 @@ def check_element_content_exact(self, element, content): return True return False + def get_elements_attribute(self, element, attribute): + """Gets ___ element's ___ attribute value.""" + for line in self.html_obj.find_all(element): + return line.attrs.get(attribute) + + def get_all_elements_attribute(self, element, attribute): + """Gets all ___ element's ___ attribute value in a list.""" + all_values = [] + for line in self.html_obj.find_all(element): + all_values.append(line.attrs.get(attribute)) + return all_values + def check_elements_attribute(self, element, attribute, value): """Does ___ element have ___ attribute with ___ value?""" for line in self.html_obj.find_all(element): @@ -157,6 +182,10 @@ class CSS_Check: get_num_declarations() - Returns the number of declarations in CSS file. """ def __init__(self, filepath, text=False): + logging.basicConfig(stream="warnings", + format='%(asctime)s %(message)s',) + newlog = logging.getLogger() + cssutils.log.setLog(newlog) if text: self.filepath = "No Filepath was provided, only text." self.css_obj = cssutils.parseString(filepath)