From 4693dbf9c12c59b59df70fca8d8789fa40904529 Mon Sep 17 00:00:00 2001 From: Akash Mahanty Date: Mon, 11 Jan 2021 09:34:37 +0530 Subject: [PATCH] change str repr of cdxsnapshot to cdx line --- tests/test_snapshot.py | 14 +++++++++++--- waybackpy/snapshot.py | 10 +++++++++- waybackpy/wrapper.py | 18 ++++++++++++++++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 5f09af1..62cc967 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -26,7 +26,15 @@ def test_CdxSnapshot(): assert properties["statuscode"] == snapshot.statuscode assert properties["digest"] == snapshot.digest assert properties["length"] == snapshot.length - assert datetime.strptime(properties["timestamp"], "%Y%m%d%H%M%S") == snapshot.datetime_timestamp - archive_url = "https://web.archive.org/web/" + properties["timestamp"] + "/" + properties["original"] + assert ( + datetime.strptime(properties["timestamp"], "%Y%m%d%H%M%S") + == snapshot.datetime_timestamp + ) + archive_url = ( + "https://web.archive.org/web/" + + properties["timestamp"] + + "/" + + properties["original"] + ) assert archive_url == snapshot.archive_url - assert archive_url == str(snapshot) + assert sample_input == str(snapshot) diff --git a/waybackpy/snapshot.py b/waybackpy/snapshot.py index e6546f3..d6797b2 100644 --- a/waybackpy/snapshot.py +++ b/waybackpy/snapshot.py @@ -25,4 +25,12 @@ class CdxSnapshot: ) def __str__(self): - return self.archive_url + return ("%s %s %s %s %s %s %s") % ( + self.urlkey, + self.timestamp, + self.original, + self.mimetype, + self.statuscode, + self.digest, + self.length, + ) diff --git a/waybackpy/wrapper.py b/waybackpy/wrapper.py index ed9dd8f..d4c7f5d 100644 --- a/waybackpy/wrapper.py +++ b/waybackpy/wrapper.py @@ -298,9 +298,23 @@ class Url: url_list = [] if subdomain: - cdx = Cdx(_cleaned_url(self.url), user_agent=self.user_agent, start_timestamp=start_timestamp, end_timestamp=end_timestamp, match_type="domain", collapses=["urlkey"]) + cdx = Cdx( + _cleaned_url(self.url), + user_agent=self.user_agent, + start_timestamp=start_timestamp, + end_timestamp=end_timestamp, + match_type="domain", + collapses=["urlkey"], + ) else: - cdx = Cdx(_cleaned_url(self.url), user_agent=self.user_agent, start_timestamp=start_timestamp, end_timestamp=end_timestamp, match_type="host", collapses=["urlkey"]) + cdx = Cdx( + _cleaned_url(self.url), + user_agent=self.user_agent, + start_timestamp=start_timestamp, + end_timestamp=end_timestamp, + match_type="host", + collapses=["urlkey"], + ) snapshots = cdx.snapshots()