Prüfe Existenz von /favicon.ico und werte dies ebenso wie ein Icon, das im HTML Head verlinkt ist (#115)
* Fix full JSON export * Update ignore list * Update README * Check for /favicon.ico and rate it as icon available * Remove broken cookies testpull/118/head
parent
9e5426ccde
commit
04a1e98b79
8 changed files with 135 additions and 58 deletions
@ -1,10 +1,8 @@ |
||||
venv |
||||
cache |
||||
webapp/node_modules |
||||
secrets |
||||
temp |
||||
__pycache__ |
||||
.vscode/settings.json |
||||
webapp/dist/bundle.js |
||||
dev-shm |
||||
/export-* |
||||
kubernetes/green-spider-secret.yaml |
||||
/volumes |
@ -0,0 +1,35 @@ |
||||
""" |
||||
Loads /favicon if no icon has been found otherwise |
||||
""" |
||||
|
||||
import logging |
||||
from time import mktime |
||||
from datetime import datetime |
||||
from urllib.parse import urlparse |
||||
|
||||
import requests |
||||
|
||||
from checks.abstract_checker import AbstractChecker |
||||
|
||||
class Checker(AbstractChecker): |
||||
def __init__(self, config, previous_results=None): |
||||
super().__init__(config, previous_results) |
||||
self.favicons = {} |
||||
|
||||
def run(self): |
||||
for url in self.config.urls: |
||||
self.load_favicon(url) |
||||
|
||||
return self.favicons |
||||
|
||||
def load_favicon(self, url): |
||||
""" |
||||
This loads /favicon.ico for the site's URL |
||||
""" |
||||
parsed = urlparse(url) |
||||
ico_url = parsed.scheme + "://" + parsed.hostname + "/favicon.ico" |
||||
r = requests.head(ico_url) |
||||
if r.status_code == 200: |
||||
self.favicons[url] = { |
||||
'url': ico_url, |
||||
} |
@ -0,0 +1,43 @@ |
||||
from pprint import pprint |
||||
|
||||
import httpretty |
||||
from httpretty import httprettified |
||||
import unittest |
||||
|
||||
from checks import load_favicons |
||||
from checks.config import Config |
||||
|
||||
@httprettified |
||||
class TestFavicons(unittest.TestCase): |
||||
|
||||
def test_favicons(self): |
||||
# This site has a favicon |
||||
url1 = 'http://example1.com/favicon.ico' |
||||
httpretty.register_uri(httpretty.HEAD, url1, |
||||
body='', |
||||
adding_headers={ |
||||
"Content-type": "image/x-ico", |
||||
}) |
||||
|
||||
# This site has no favicon |
||||
url2 = 'http://example2.com/favicon.ico' |
||||
httpretty.register_uri(httpretty.HEAD, url2, |
||||
status=404, |
||||
body='Not found', |
||||
adding_headers={ |
||||
"Content-type": "text/plain", |
||||
}) |
||||
|
||||
|
||||
config = Config(urls=['http://example1.com/path/', 'http://example2.com/']) |
||||
checker = load_favicons.Checker(config=config) |
||||
|
||||
result = checker.run() |
||||
pprint(result) |
||||
|
||||
self.assertEqual(result, { |
||||
'http://example1.com/path/': { |
||||
'url': 'http://example1.com/favicon.ico' |
||||
} |
||||
}) |
||||
|
Loading…
Reference in new issue