Skip to content

Commit

Permalink
Update htmlcssgrade.py
Browse files Browse the repository at this point in the history
Add bug fix for logging warnings failing test cases and also added the two feature requests.
  • Loading branch information
MrMazzone committed Jul 13, 2023
1 parent ee10c8c commit dc32836
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion htmlcssgrade.py
Original file line number Diff line number Diff line change
@@ -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:
"""
Expand Down Expand Up @@ -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?"""
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit dc32836

Please sign in to comment.