fix: pylint errors were pointed out by codacy

This commit is contained in:
eggplants
2022-02-05 03:58:23 +09:00
parent d8cabdfdb5
commit d058432bb0
3 changed files with 39 additions and 30 deletions

View File

@@ -26,27 +26,25 @@ class WaybackMachineCDXServerAPI(object):
user_agent: str = DEFAULT_USER_AGENT, user_agent: str = DEFAULT_USER_AGENT,
start_timestamp: Optional[str] = None, start_timestamp: Optional[str] = None,
end_timestamp: Optional[str] = None, end_timestamp: Optional[str] = None,
filters: List[str] = [], filters: Optional[List[str]] = None,
match_type: Optional[str] = None, match_type: Optional[str] = None,
gzip: Optional[str] = None, gzip: Optional[str] = None,
collapses: List[str] = [], collapses: Optional[List[str]] = None,
limit: Optional[str] = None, limit: Optional[str] = None,
max_tries: int = 3, max_tries: int = 3,
) -> None: ) -> None:
self.url = str(url).strip().replace(" ", "%20") self.url = str(url).strip().replace(" ", "%20")
self.user_agent = user_agent self.user_agent = user_agent
self.start_timestamp = ( self.start_timestamp = None if start_timestamp is None else str(start_timestamp)
str(start_timestamp) if start_timestamp is not None else None self.end_timestamp = None if end_timestamp is None else str(end_timestamp)
) self.filters = [] if filters is None else filters
self.end_timestamp = str(end_timestamp) if end_timestamp is not None else None
self.filters = filters
check_filters(self.filters) check_filters(self.filters)
self.match_type = str(match_type).strip() if match_type is not None else None self.match_type = None if match_type is None else str(match_type).strip()
check_match_type(self.match_type, self.url) check_match_type(self.match_type, self.url)
self.gzip = gzip self.gzip = gzip
self.collapses = collapses self.collapses = [] if collapses is None else collapses
check_collapses(self.collapses) check_collapses(self.collapses)
self.limit = limit if limit is not None else 5000 self.limit = 5000 if limit is None else limit
self.max_tries = max_tries self.max_tries = max_tries
self.last_api_request_url: Optional[str] = None self.last_api_request_url: Optional[str] = None
self.use_page = False self.use_page = False

View File

@@ -16,7 +16,6 @@ from .utils import DEFAULT_USER_AGENT
from .wrapper import Url from .wrapper import Url
@click.command()
@click.option( @click.option(
"-u", "--url", help="URL on which Wayback machine operations are to be performed." "-u", "--url", help="URL on which Wayback machine operations are to be performed."
) )
@@ -29,7 +28,13 @@ from .wrapper import Url
) )
@click.option("-v", "--version", is_flag=True, default=False, help="waybackpy version.") @click.option("-v", "--version", is_flag=True, default=False, help="waybackpy version.")
@click.option( @click.option(
"-l", "--license", is_flag=True, default=False, help="license of Waybackpy." "-l",
"--license",
"--show-license",
"--show_license",
is_flag=True,
default=False,
help="license of Waybackpy.",
) )
@click.option( @click.option(
"-n", "-n",
@@ -125,6 +130,8 @@ from .wrapper import Url
@click.option( @click.option(
"-f", "-f",
"--filter", "--filter",
"--cdx-filter",
"--cdx_filter",
multiple=True, multiple=True,
help="Filter on a specific field or all the CDX fields.", help="Filter on a specific field or all the CDX fields.",
) )
@@ -163,11 +170,11 @@ from .wrapper import Url
+ "if this parameter is not used then the plain text response of the CDX API " + "if this parameter is not used then the plain text response of the CDX API "
+ "will be printed.", + "will be printed.",
) )
def main( def _main(
url: Optional[str], url: Optional[str],
user_agent: str, user_agent: str,
version: bool, version: bool,
license: bool, show_license: bool,
newest: bool, newest: bool,
oldest: bool, oldest: bool,
json: bool, json: bool,
@@ -185,7 +192,7 @@ def main(
cdx: bool, cdx: bool,
start_timestamp: Optional[str], start_timestamp: Optional[str],
end_timestamp: Optional[str], end_timestamp: Optional[str],
filter: List[str], cdx_filter: List[str],
match_type: Optional[str], match_type: Optional[str],
gzip: Optional[str], gzip: Optional[str],
collapse: List[str], collapse: List[str],
@@ -218,7 +225,7 @@ def main(
click.echo(f"waybackpy version {__version__}") click.echo(f"waybackpy version {__version__}")
return return
if license: if show_license:
click.echo( click.echo(
requests.get( requests.get(
url="https://raw.githubusercontent.com/akamhy/waybackpy/master/LICENSE" url="https://raw.githubusercontent.com/akamhy/waybackpy/master/LICENSE"
@@ -344,7 +351,7 @@ def main(
click.echo(url) click.echo(url)
if cdx: if cdx:
filters = list(filter) filters = list(cdx_filter)
collapses = list(collapse) collapses = list(collapse)
cdx_print = list(cdx_print) cdx_print = list(cdx_print)
@@ -397,5 +404,9 @@ def main(
click.echo(output_string) click.echo(output_string)
def main() -> None:
click.command()(_main)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@@ -6,6 +6,8 @@ from .cdx_api import WaybackMachineCDXServerAPI
from .save_api import WaybackMachineSaveAPI from .save_api import WaybackMachineSaveAPI
from .utils import DEFAULT_USER_AGENT from .utils import DEFAULT_USER_AGENT
class Url(object):
""" """
The Url class is not recommended to be used anymore, instead use the The Url class is not recommended to be used anymore, instead use the
WaybackMachineSaveAPI, WaybackMachineAvailabilityAPI and WaybackMachineCDXServerAPI. WaybackMachineSaveAPI, WaybackMachineAvailabilityAPI and WaybackMachineCDXServerAPI.
@@ -19,8 +21,6 @@ do not use the Url class for new code as it would be removed after 2025 also the
update the older interface code. update the older interface code.
""" """
class Url(object):
def __init__(self, url: str, user_agent: str = DEFAULT_USER_AGENT) -> None: def __init__(self, url: str, user_agent: str = DEFAULT_USER_AGENT) -> None:
self.url = url self.url = url
self.user_agent = str(user_agent) self.user_agent = str(user_agent)