support unix ts as an arg in near

This commit is contained in:
Akash Mahanty 2021-01-11 19:53:37 +05:30
parent 4693dbf9c1
commit 5a7bd73565
2 changed files with 17 additions and 9 deletions

View File

@ -11,6 +11,9 @@ quote = requests.utils.quote
default_user_agent = "waybackpy python package - https://github.com/akamhy/waybackpy"
def _unix_ts_to_wayback_ts(unix_ts):
return datetime.utcfromtimestamp(int(unix_ts)).strftime('%Y%m%d%H%M%S')
def _add_payload(self, payload):
if self.start_timestamp:
payload["from"] = self.start_timestamp

View File

@ -11,6 +11,7 @@ from .utils import (
_url_check,
_cleaned_url,
_ts,
_unix_ts_to_wayback_ts,
)
@ -165,7 +166,7 @@ class Url:
return response.content.decode(encoding.replace("text/html", "UTF-8", 1))
def near(self, year=None, month=None, day=None, hour=None, minute=None):
def near(self, year=None, month=None, day=None, hour=None, minute=None, unix_timestamp=None):
"""
Wayback Machine can have many archives of a webpage,
sometimes we want archive close to a specific time.
@ -187,6 +188,10 @@ class Url:
And finally return self.
"""
if unix_timestamp:
timestamp = _unix_ts_to_wayback_ts(unix_timestamp)
else:
now = datetime.utcnow().timetuple()
timestamp = _wayback_timestamp(
year=year if year else now.tm_year,