Revert "Use datetime.datetime in _wayback_timestamp"

This reverts commit 5b30380865.

Introduced unnecessary complexity
This commit is contained in:
AntiCompositeNumber
2020-07-21 22:08:15 -04:00
parent 44740c6bf4
commit 37f5c18506

View File

@@ -36,9 +36,11 @@ def _archive_url_parser(header):
) )
def _wayback_timestamp(dt): def _wayback_timestamp(**kwargs):
"""Return a formatted timestamp.""" """Return a formatted timestamp."""
return dt.strftime("%Y%m%d%h%m") return "".join(
str(kwargs[key]).zfill(2) for key in ["year", "month", "day", "hour", "minute"]
)
class Url: class Url:
@@ -111,14 +113,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.
""" """
kwargs = { now = datetime.utcnow().timetuple()
key: val timestamp = _wayback_timestamp(
for key, val in dict( year=year if year else now.tm_year,
year=year, month=month, day=day, hour=hour, minute=minute month=month if month else now.tm_mon,
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(),