from terroroftinytown.services.base import BaseService, html_unescape
import re
from terroroftinytown.services.status import URLStatus
from terroroftinytown.client.errors import UnexpectedNoResult
class AdjixService(BaseService):
def process_redirect(self, response):
if '
Spammer' in response.text or \
'Phisher' in response.text or \
'It has automatically been terminated.' in response.text or \
'This link was created by a spammer' in response.text or \
'This link was created by an unknown spammer' in response.text or \
'This link was abused by' in response.text or \
'Abuse' in response.text or \
'Link Removed' in response.text or \
'Phishing Link' in response.text or \
'TOS' in response.text:
return (URLStatus.unavailable, None, None)
if not response.text.strip():
return (URLStatus.not_found, None, None)
groups = re.findall((
r'CONTENT="\d+;URL=(.*)(?:\r\n|">)|'
')|'
'rel="canonical" href="(.*)"/>'
),
response.text
)
for group in groups:
text = group[0] or group[1] or group[2]
link = html_unescape(text)
if 'ad.adjix.com' in link:
continue
return (URLStatus.ok, link, response.encoding)
for group in groups:
text = group[0] or group[1] or group[2]
link = html_unescape(text)
return (URLStatus.ok, link, response.encoding)
raise UnexpectedNoResult(
"Didn't get anything for {0}".format(self.current_shortcode))