alturl.py 1.0 KB

12345678910111213141516171819202122232425262728
  1. from terroroftinytown.services.base import BaseService, html_unescape
  2. import re
  3. from terroroftinytown.client.errors import UnexpectedNoResult
  4. from terroroftinytown.services.status import URLStatus
  5. class AlturlService(BaseService):
  6. def process_unavailable(self, response):
  7. if response.status_code != 410:
  8. return BaseService.process_unavailable(self, response)
  9. match = re.search(r'was forwarding to: <BR> <font color=red>(.*)</font>', response.text)
  10. if not match:
  11. if re.search(r'This shortURL address was REMOVED for SPAMMING', response.text):
  12. return URLStatus.unavailable, None, None
  13. if not match and 'REMOVED FOR SPAMMING' in response.text:
  14. return URLStatus.unavailable, None, None
  15. if not match:
  16. raise UnexpectedNoResult(
  17. "Could not find target URL on blocked page for {0}"
  18. .format(self.current_shortcode))
  19. url = html_unescape(match.group(1))
  20. return URLStatus.ok, url, response.encoding