Skip to content

Commit

Permalink
make calling BNF archives functional (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Ooghe committed Jun 17, 2021
1 parent 64ebf24 commit 818d24e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions hyphe_backend/crawler/hcicrawler/spiders/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def handle_response(self, response):
response.meta['depth'] -= 1
else:
response.meta['depth'] = -1
return self._request(redir_url)
return self._request(redir_url, redirection=True)
real_url = self.archiveregexp.sub("", redir_url)
orig_url = self.archiveregexp.sub("", response.url)
match = self.archiveregexp.search(redir_url)
Expand Down Expand Up @@ -390,7 +390,7 @@ def _should_follow(self, depth, tolru):
c2 = self.prefixes_trie.match_lru(tolru)
return c1 and c2

def _request(self, url, noproxy=False, **kw):
def _request(self, url, noproxy=False, redirection=False, **kw):
kw['meta'] = {'handle_httpstatus_all': True, 'noproxy': noproxy}
kw['callback'] = self.handle_response
kw['errback'] = self.handle_error
Expand All @@ -403,7 +403,9 @@ def _request(self, url, noproxy=False, **kw):
kw['headers'] = {
"BnF-OSWM-User-Name": "WS-HYPHE_%s_%s" % (HYPHE_PROJECT, self.job)
}
return Request("%s/%s/%s" % (ARCHIVES["URL_PREFIX"], self.archivedate, url), **kw)
if url.startswith(ARCHIVES["URL_PREFIX"]) or redirection:
return Request(url, **kw)
return Request("%s/%s/%s" % (ARCHIVES["URL_PREFIX"].rstrip('/'), self.archivedate, url), **kw)
if url.startswith(ARCHIVES["URL_PREFIX"]):
kw["meta"]["archive_timestamp"] = self.archiveregexp.search(url).group(1)
return Request(url, **kw)
Expand Down

0 comments on commit 818d24e

Please sign in to comment.