renamed some func/meth to better names and added doc strings + lint

This commit is contained in:
Akash Mahanty
2021-01-25 21:11:49 +05:30
parent d1061bfdc8
commit 0a241818ff
3 changed files with 28 additions and 16 deletions

View File

@@ -5,6 +5,7 @@ import json
import random import random
import string import string
import argparse import argparse
from .wrapper import Url from .wrapper import Url
from .exceptions import WaybackError from .exceptions import WaybackError
from .__version__ import __version__ from .__version__ import __version__

View File

@@ -1,12 +1,13 @@
import re import re
import time import time
import requests import requests
from .exceptions import WaybackError, URLError
from datetime import datetime from datetime import datetime
from .exceptions import WaybackError, URLError
from .__version__ import __version__
from urllib3.util.retry import Retry from urllib3.util.retry import Retry
from requests.adapters import HTTPAdapter from requests.adapters import HTTPAdapter
from .__version__ import __version__
quote = requests.utils.quote 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"
@@ -35,7 +36,7 @@ def _latest_version(package_name, headers):
return json["info"]["version"] return json["info"]["version"]
def _unix_ts_to_wayback_ts(unix_timestamp): def _unix_timestamp_to_wayback_timestamp(unix_timestamp):
"""Returns unix timestamp converted to datetime.datetime """Returns unix timestamp converted to datetime.datetime
Parameters Parameters
@@ -85,18 +86,27 @@ def _add_payload(instance, payload):
for i, f in enumerate(instance.collapses): for i, f in enumerate(instance.collapses):
payload["collapse" + str(i)] = f payload["collapse" + str(i)] = f
# Don't need to return anything as it's dictionary.
payload["url"] = instance.url payload["url"] = instance.url
def _ts(timestamp, data): def _timestamp_manager(timestamp, data):
""" """Returns the timestamp.
Get timestamp of last fetched archive.
If used before fetching any archive, will
use whatever self.JSON returns.
self.timestamp is None implies that Parameters
self.JSON will return any archive's JSON ----------
that wayback machine provides it. timestamp : datetime.datetime
datetime object
data : dict
A python dictionary, which is loaded JSON os the availability API.
Return type:
datetime.datetime
If timestamp is not None then sets the value to timestamp itself.
If timestamp is None the returns the value from the last fetched API data.
If not timestamp and can not read the archived_snapshots form data return datetime.max
""" """
if timestamp: if timestamp:

View File

@@ -1,5 +1,6 @@
import re import re
from datetime import datetime, timedelta from datetime import datetime, timedelta
from .exceptions import WaybackError from .exceptions import WaybackError
from .cdx import Cdx from .cdx import Cdx
from .utils import ( from .utils import (
@@ -9,8 +10,8 @@ from .utils import (
default_user_agent, default_user_agent,
_url_check, _url_check,
_cleaned_url, _cleaned_url,
_ts, _timestamp_manager,
_unix_ts_to_wayback_ts, _unix_timestamp_to_wayback_timestamp,
_latest_version, _latest_version,
) )
@@ -121,8 +122,8 @@ class Url:
@property @property
def _timestamp(self): def _timestamp(self):
self.timestamp = _ts(self.timestamp, self.JSON) """Sets the value of self.timestamp if still not set."""
return self.timestamp return _timestamp_manager(self.timestamp, self.JSON)
def save(self): def save(self):
""" """
@@ -237,7 +238,7 @@ class Url:
""" """
if unix_timestamp: if unix_timestamp:
timestamp = _unix_ts_to_wayback_ts(unix_timestamp) timestamp = _unix_timestamp_to_wayback_timestamp(unix_timestamp)
else: else:
now = datetime.utcnow().timetuple() now = datetime.utcnow().timetuple()
timestamp = _wayback_timestamp( timestamp = _wayback_timestamp(