Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/models/heuristics/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__all__ = ["documentlength", "easeofnavigation", "mobileaccessibility", "mobilereadability", "plainlanguage", "typeconventions"]
__all__ = ["documentlength", "easeofnavigation", "mobileaccessibility", "mobilereadability", "plainlanguage", "typeconventions", "directpresentation"]
51 changes: 51 additions & 0 deletions api/models/heuristics/directpresentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from models.heuristic import Heuristic
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from boilerpipe.extract import Extractor
from multiprocessing import RLock
from bs4 import BeautifulSoup, SoupStrainer
import re

# Procedural 2q
# Ensure link to EULA can be found on home page
class DirectPresentation(Heuristic):
def score(self, eula):
if eula.url is None:
return {'score': -1, 'max': 4, 'reason': 'no url'}
else:
url = eula.url
suffixes = [".com", ".net", ".org"]
for i in suffixes:
n = url.find(i)
if n != -1:
break
url = url[0:n+4]

chrome_options = Options()
chrome_options.add_argument("--hide-scrollbars")
chrome_options.set_headless()

# Start chrome driver, and set window to initial width and height
driver = webdriver.Chrome(chrome_options=chrome_options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should think about using Scrapy instead of chrome unless we need to render the page. Chrome headless has a huge memory overhead and high cpu load.

driver.set_window_size(1920, 1080)

# Grab desktop view
driver.get(url)
html = driver.page_source

pattern = re.compile(r'terms')
soup = BeautifulSoup(html, 'html.parser')
search = soup.findAll('a', href=True, text=re.compile(r'end\W*user\W*license', re.I))
if len(search) == 1:
return {'score': 4, 'max': 4, 'eula_found': search[0]['href']}
elif len(search) > 1:
return {'score': 4, 'max': 4, 'possible_eulas': search}

search = soup.findAll('a', href=True, text=re.compile(r'terms', re.I))
if len(search) == 1:
return {'score': 4, 'max': 4, 'eula_found': search[0]['href']}
elif len(search) > 1:
return {'score': 4, 'max': 4, 'possible_eulas': search}

return {'score': 0, 'max': 4, 'reason': 'Could not find link to EULA on homepage'}
4 changes: 2 additions & 2 deletions api/models/procedural.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Procedural(Category):

def evaluate(self, eula, thread_semaphore, ret_vars):
# List of heuristics to evaluate, and the relative weighting of each
heuristics_to_eval = [mobileaccessibility.MobileAccessibility, mobilereadability.MobileReadability]
heuristic_weights = {'mobileaccessibility': 2, 'mobilereadability': 5}
heuristics_to_eval = [mobileaccessibility.MobileAccessibility, mobilereadability.MobileReadability, directpresentation.DirectPresentation]
heuristic_weights = {'mobileaccessibility': 2, 'mobilereadability': 5, "directpresentation" : 3}

ret_vars['procedural'] = self.parallel_evaluate(eula, heuristics_to_eval, heuristic_weights, thread_semaphore)