green-spider/rating/contact_link.py
Marian Steinbach d0e3a4210f
Fix link raters (social media links, contact link) (#95)
* Fix rating for contact_link and social_media_link

* Skip checks when dependencies not met
2018-11-28 23:46:40 +01:00

44 lines
1 KiB
Python

"""
Checks whether the pages has a link "Kontakt"
"""
from rating.abstract_rater import AbstractRater
class Rater(AbstractRater):
rating_type = 'boolean'
default_value = False
depends_on_checks = ['hyperlinks']
max_score = 1
def __init__(self, check_results):
super().__init__(check_results)
def rate(self):
value = self.default_value
score = 0
urls = 0
urls_with_contact_link = 0
for url in self.check_results['hyperlinks']:
urls += 1
for link in self.check_results['hyperlinks'][url]['links']:
if link['text'].lower() == 'kontakt':
urls_with_contact_link += 1
# make sure we only count 1 for this url
break
if urls > 0 and urls_with_contact_link == urls:
score = self.max_score
value = True
return {
'type': self.rating_type,
'value': value,
'score': score,
'max_score': self.max_score,
}