Commit 60c8c0ff authored by Stefan Karner's avatar Stefan Karner

Refactor method names

parent 8dc2b37d
......@@ -107,8 +107,9 @@ class WebarchivSession:
print(self._error_template.format(status_code=e.response.status_code,
response_text=e.response.text),
file=sys.stderr)
def _handle_response_errors(self, r):
@staticmethod
def _handle_response_errors(r):
if r.status_code == 403:
print('Forbidden. Invalid Token or ApiKey transmitted', file=sys.stderr)
return r
......@@ -166,7 +167,7 @@ class WebarchivSession:
try:
response = self._get(op='/search/fulltext', params=params)
return self.waitForResponse(response)
return self.wait_for_response(response)
except HTTPError as e:
self._display_http_error(e)
......@@ -192,7 +193,7 @@ class WebarchivSession:
try:
response = self._get(op='/search/fulltext/seed', params=params)
return self.waitForResponse(response)
return self.wait_for_response(response)
except HTTPError as e:
self._display_http_error(e)
......@@ -217,7 +218,7 @@ class WebarchivSession:
try:
response = self._get(op='/search/fulltext/capture', params=params)
return self.waitForResponse(response)
return self.wait_for_response(response)
except HTTPError as e:
self._display_http_error(e)
......@@ -241,13 +242,13 @@ class WebarchivSession:
try:
response = self._get(op='/search/wayback', params=params)
return self.waitForResponse(response)
return self.wait_for_response(response)
except HTTPError as e:
self._display_http_error(e)
print('Error:'.format(query_string))
def waitForResponse(self, response):
def wait_for_response(self, response):
"""
Polls until the server responds with a result
"""
......@@ -296,7 +297,7 @@ class WebarchivSession:
try:
response = self._get(op='/search/domainname', params=params)
return self.waitForResponse(response)
return self.wait_for_response(response)
except HTTPError as e:
self._display_http_error(e)
......@@ -319,30 +320,30 @@ class WebarchivSession:
try:
response = self._get(op='/search/fulltext/histogram', params=params)
return self.waitForResponse(response)
return self.wait_for_response(response)
except HTTPError as e:
self._display_http_error(e)
print('Error:'.format(query_string))
def getSnapshotUrl(self, seed, capture, onlysvg):
def get_snapshot_url(self, seed, capture, onlysvg):
return self.api_path + 'snapshot?capture=' + capture + '&t=' + self.token + '&apikey=' + self.api_key + '&onlysvg=' + onlysvg + '&seed=' + seed
@staticmethod
def resultContainsSeeds(response):
def result_contains_seeds(response):
try:
return response.json()['subtype'] == 2
except:
return False
@staticmethod
def resultContainsCaptures(response):
def result_contains_captures(response):
try:
return response.json()['subtype'] == 3
except:
return False
def savePage(self, url):
def save_page(self, url):
self.connect()
r = requests.post(self.base_url.format('savepage'),
data='''{{
......@@ -357,7 +358,7 @@ class WebarchivSession:
)
return r
def fragmentChecksumHtml(self, seed, capture, selector, occurrence):
def fragment_checksum_html(self, seed, capture, selector, occurrence):
try:
response = self._post(op='/fragment/checksum/html', json={
"seed": seed,
......@@ -367,7 +368,7 @@ class WebarchivSession:
"extractortype": EXTRACTOR_HTML
})
response = self.status_query(response)
return self.waitForResponse(response)
return self.wait_for_response(response)
except HTTPError as e:
self._display_http_error(e)
......@@ -393,7 +394,7 @@ if __name__ == '__main__':
for capture in response.json()['hits']:
capturedate = capture['c']
resp = w.fragmentChecksumHtml(url, capturedate, ".odd td", 3)
resp = w.fragment_checksum_html(url, capturedate, ".odd td", 3)
checksum = resp.json()['checksum']
returncode = resp.json()['returncode']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment