This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4920 from jwhitlock/scrape-zones-no-more-1462475
bug 1462475: Remove zone scraping
- Loading branch information
Showing
14 changed files
with
197 additions
and
792 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""DocumentRedirectSource checks if a MDN wiki document is a redirect.""" | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
from django.utils.six.moves.urllib.parse import urlparse | ||
|
||
from .base import DocumentBaseSource | ||
|
||
|
||
class DocumentRedirectSource(DocumentBaseSource): | ||
"""Request the rendered document, to detect redirects.""" | ||
|
||
def source_path(self): | ||
return '/%s/docs/%s' % (self.locale, self.slug) | ||
|
||
def load_prereqs(self, requester, storage): | ||
"""Request the document, and process the redirects and response.""" | ||
response = requester.request(self.source_path(), | ||
raise_for_status=False, | ||
method='HEAD') | ||
if response.status_code not in (200, 301, 302): | ||
raise self.SourceError('status_code %s', response.status_code) | ||
data = {} | ||
|
||
# Is this a redirect? | ||
if response.history: | ||
redirect_from = urlparse(response.history[0].url).path | ||
redirect_to = urlparse(response.url).path | ||
if redirect_to != redirect_from: | ||
data['redirect_to'] = self.decode_href(redirect_to) | ||
|
||
return True, data | ||
|
||
def save_data(self, storage, data): | ||
"""Save the rendered document data.""" | ||
storage.save_document_redirect(self.locale, self.slug, data) | ||
return [] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.