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" 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): def _add_payload(self, payload):
if self.start_timestamp: if self.start_timestamp:
payload["from"] = self.start_timestamp payload["from"] = self.start_timestamp

View File

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