Use datetime.datetime in _wayback_timestamp

This commit is contained in:
AntiCompositeNumber 2020-07-21 17:14:38 -04:00
parent 9dfb87fae3
commit 5b30380865
No known key found for this signature in database
GPG Key ID: A888A323AB506229

View File

@ -36,11 +36,9 @@ def _archive_url_parser(header):
) )
def _wayback_timestamp(**kwargs): def _wayback_timestamp(dt):
"""Return a formatted timestamp.""" """Return a formatted timestamp."""
return "".join( return dt.strftime("%Y%m%d%h%m")
str(kwargs[key]).zfill(2) for key in ["year", "month", "day", "hour", "minute"]
)
class Url: class Url:
@ -113,14 +111,14 @@ class Url:
Supported params are year, month, day, hour and minute. Supported params are year, month, day, hour and minute.
Any non-supplied parameters default to the current time. Any non-supplied parameters default to the current time.
""" """
now = datetime.utcnow().timetuple() kwargs = {
timestamp = _wayback_timestamp( key: val
year=year if year else now.tm_year, for key, val in dict(
month=month if month else now.tm_mon, year=year, month=month, day=day, hour=hour, minute=minute
day=day if day else now.tm_mday,
hour=hour if hour else now.tm_hour,
minute=minute if minute else now.tm_min,
) )
if val is not None
}
timestamp = _wayback_timestamp(datetime.utcnow().replace(**kwargs))
request_url = "https://archive.org/wayback/available?url=%s&timestamp=%s" % ( request_url = "https://archive.org/wayback/available?url=%s&timestamp=%s" % (
self._clean_url(), self._clean_url(),