Skip to content

Commit

Permalink
Extended parked API to give info about redirections
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismyrobot committed Jul 2, 2016
1 parent e035f49 commit 3a9d038
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
6 changes: 4 additions & 2 deletions dnstwister/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ def parked_score(hexdomain):
'Malformed domain or domain not represented in hexadecimal format.'
)
payload = standard_api_values(domain, skip='parked_score')
score = parked.get_score(domain)
score, score_text, redirects, dest = parked.get_score(domain)
payload['score'] = score
payload['score_text'] = parked.get_text(score)
payload['score_text'] = score_text
payload['redirects'] = redirects
payload['redirects_to'] = dest
return flask.jsonify(payload)


Expand Down
19 changes: 13 additions & 6 deletions dnstwister/api/checks/parked.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ def get_score(domain):
score = 0

try:
redirects, landed_domain1, content = _domain_redirects(domain)
if redirects:
redirects_domain, landed_domain1, content = _domain_redirects(domain)
if redirects_domain:
score += 1
except requests.ConnectionError:
return 0

try:
redirects, landed_domain2, _ = _domain_redirects(
redirects_paths, landed_domain2, _ = _domain_redirects(
domain, 'dnstwister_parked_check'
)
except requests.ConnectionError:
return 0

if redirects:
if redirects_paths:
score += 1

if landed_domain1 == landed_domain2 and redirects:
if landed_domain1 == landed_domain2 and redirects_paths:
score += 1

word_score = 0
Expand All @@ -78,4 +78,11 @@ def get_score(domain):
word_score += 1.0
score += (word_score / len(PARKED_WORDS)) * 3

return round(score / 6.0, 2)
normalised_score = round(score / 6.0, 2)

return (
normalised_score,
get_text(normalised_score),
redirects_domain,
landed_domain1 if redirects_domain else '',
)
4 changes: 4 additions & 0 deletions tests/api/test_api_parked.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def test_not_parked(f_httpretty, webapp):

assert response['score'] == 0.0
assert response['score_text'] == 'Unlikely'
assert not response['redirects']
assert response['redirects_to'] == ''


def test_parked(f_httpretty, webapp):
Expand Down Expand Up @@ -59,3 +61,5 @@ def test_parked(f_httpretty, webapp):

assert response['score'] == 0.58
assert response['score_text'] == 'Fairly likely'
assert response['redirects']
assert response['redirects_to'] == 'forsale.com'

0 comments on commit 3a9d038

Please sign in to comment.