owly.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import re
  2. from terroroftinytown.client.errors import UnexpectedNoResult
  3. from terroroftinytown.services.base import BaseService, html_unescape
  4. from terroroftinytown.services.status import URLStatus
  5. class OwlyService(BaseService):
  6. def process_unknown_code(self, response):
  7. if response.status_code != 200:
  8. return BaseService.process_unknown_code(self, response)
  9. url = self.params['url_template'].format(shortcode=self.current_shortcode)
  10. response = self.fetch_url(url, 'get')
  11. if response.status_code != 200:
  12. raise UnexpectedNoResult(
  13. "Didn't get OK on second try. Got {0} for {1}"
  14. .format(response.status_code, self.current_shortcode)
  15. )
  16. # Copied form tinyback. I don't think code will reach here anymore
  17. match = re.search(
  18. "<a class=\"btn ignore\" href=\"(.*?)\" title=",
  19. html_unescape(response.text)
  20. )
  21. if not match:
  22. raise UnexpectedNoResult(
  23. "Didn't get match on second try for {0}"
  24. .format(self.current_shortcode)
  25. )
  26. return (URLStatus.ok, match.group(1), response.encoding)