googl.py 1.2 KB

123456789101112131415161718192021222324252627
  1. from terroroftinytown.services.base import BaseService
  2. from terroroftinytown.services.status import URLStatus
  3. import re
  4. class GooglService(BaseService):
  5. def process_response(self, response):
  6. status_code = response.status_code
  7. if status_code in self.params['redirect_codes']:
  8. if self.ratelimited(response):
  9. return self.process_banned(response)
  10. return self.process_redirect(response)
  11. elif status_code in self.params['no_redirect_codes']:
  12. return self.process_no_redirect(response)
  13. elif status_code in self.params['unavailable_codes']:
  14. return self.process_unavailable(response)
  15. elif status_code in self.params['banned_codes']:
  16. return self.process_banned(response)
  17. else:
  18. return self.process_unknown_code(response)
  19. def ratelimited(self, response):
  20. if 'Location' not in response.headers:
  21. return False
  22. result_url = response.headers['Location']
  23. response.content # read the response to allow connection reuse
  24. return not not re.search('^https?://(?:www\.)?google\.com/sorry/index\?continue=https://goo.gl/[^&]+&q=', result_url)