green-spider/rating/__init__.py

64 lines
1.8 KiB
Python
Raw Normal View History

"""
The rating module contains the functionality to get calculate score for certain
criteria based on information gather by checks before.
"""
import logging
from rating import canonical_url
from rating import contact_link
from rating import favicon
from rating import feeds
from rating import https
Job-Verwaltung mit RQ, und vieles mehr (#149) * CLI: remove 'jobs' command, add 'manager' * Add job definition * Move jobs to manage folder * Rename jobs to manager * Add rq and redis dependencies * Add docker-compose YAML * Downgrade to alpine 3.8 * Adjust paths in Dockerfile, remove entrypoint * Rename 'make spiderjobs' to 'make jobs' * Fix docker exectution * Adapt 'make jobs' * Fix metadata scheme * Add docker dependency * Rendomize queue (a bit) * Use latest image, remove debug output * Make docker-compose file downwards-compatible * Use latest instead of dev image tag * Update docker-compose.yaml * Adapt job start script * Fix redis connection in manager * Add support for increasing timeout via environment variable * Adapt load_in_browser to cookies table schema change * Fix execution * Mitigate yaml warning * Bump some dependency versions * Report resource usage stats for each job * checks/load_in_browser: Return DOM size, prevent multiple page loads * Update .dockerignore * Code update * Script update * Update README.md * WIP * WIP commit * Update Dockerfile to alpine:edge and chromium v90 * Update TestCertificateChecker * Set defaults for __init__ function * Detect sunflower theme * Update unit test for new datetime (zero-basing) * Set logging prefs from Chromium in a new way * Move datastore client instantiation As it is not needed for all commands * Change green-directory repository URL * Add git settings for cloning green-directory * Pin alpine version 3.14, fix py3-cryptography * Use plain docker build progress output * Add volumes to 'make test' docker run command * Fix bug * Update example command in README * Update dependencies * Add creation of Kubernetes jobs
2021-11-11 20:15:43 +01:00
from rating import network_payload
from rating import network_requests
from rating import no_network_errors
from rating import no_script_errors
2019-04-29 10:09:25 +02:00
from rating import no_third_party_cookies
from rating import reachable
from rating import resolvable
from rating import response_duration
from rating import responsive_layout
from rating import social_media_links
from rating import use_specific_fonts
from rating import www_optional
def calculate_rating(results):
"""
Calculates ratings for a number of criteria.
Params:
results - Results dictionary from checks
"""
# The raters to execute.
rating_modules = {
'CANONICAL_URL': canonical_url,
'CONTACT_LINK': contact_link,
'DNS_RESOLVABLE_IPV4': resolvable,
'FAVICON': favicon,
'FEEDS': feeds,
'HTTPS': https,
'HTTP_RESPONSE_DURATION': response_duration,
Job-Verwaltung mit RQ, und vieles mehr (#149) * CLI: remove 'jobs' command, add 'manager' * Add job definition * Move jobs to manage folder * Rename jobs to manager * Add rq and redis dependencies * Add docker-compose YAML * Downgrade to alpine 3.8 * Adjust paths in Dockerfile, remove entrypoint * Rename 'make spiderjobs' to 'make jobs' * Fix docker exectution * Adapt 'make jobs' * Fix metadata scheme * Add docker dependency * Rendomize queue (a bit) * Use latest image, remove debug output * Make docker-compose file downwards-compatible * Use latest instead of dev image tag * Update docker-compose.yaml * Adapt job start script * Fix redis connection in manager * Add support for increasing timeout via environment variable * Adapt load_in_browser to cookies table schema change * Fix execution * Mitigate yaml warning * Bump some dependency versions * Report resource usage stats for each job * checks/load_in_browser: Return DOM size, prevent multiple page loads * Update .dockerignore * Code update * Script update * Update README.md * WIP * WIP commit * Update Dockerfile to alpine:edge and chromium v90 * Update TestCertificateChecker * Set defaults for __init__ function * Detect sunflower theme * Update unit test for new datetime (zero-basing) * Set logging prefs from Chromium in a new way * Move datastore client instantiation As it is not needed for all commands * Change green-directory repository URL * Add git settings for cloning green-directory * Pin alpine version 3.14, fix py3-cryptography * Use plain docker build progress output * Add volumes to 'make test' docker run command * Fix bug * Update example command in README * Update dependencies * Add creation of Kubernetes jobs
2021-11-11 20:15:43 +01:00
'NETWORK_PAYLOAD': network_payload,
'NETWORK_REQUESTS': network_requests,
'NO_NETWORK_ERRORS': no_network_errors,
'NO_SCRIPT_ERRORS': no_script_errors,
2019-04-29 10:09:25 +02:00
'NO_THIRD_PARTY_COOKIES': no_third_party_cookies,
'RESPONSIVE': responsive_layout,
'SITE_REACHABLE': reachable,
'SOCIAL_MEDIA_LINKS': social_media_links,
'USE_SPECIFIC_FONTS': use_specific_fonts,
'WWW_OPTIONAL': www_optional,
}
output = {}
for name in rating_modules:
rater = rating_modules[name].Rater(results)
output[name] = rater.rate()
return output