lint and refactor cli module
This commit is contained in:
parent
d58a5f0ee5
commit
1216ffbc70
@ -59,20 +59,20 @@ def save_urls_on_file(url_gen: Generator[str, None, None]) -> None:
|
|||||||
for url in url_gen:
|
for url in url_gen:
|
||||||
url_count += 1
|
url_count += 1
|
||||||
if not domain:
|
if not domain:
|
||||||
m = re.search("https?://([A-Za-z_0-9.-]+).*", url)
|
match = re.search("https?://([A-Za-z_0-9.-]+).*", url)
|
||||||
|
|
||||||
domain = "domain-unknown"
|
domain = "domain-unknown"
|
||||||
|
|
||||||
if m:
|
if match:
|
||||||
domain = m.group(1)
|
domain = match.group(1)
|
||||||
|
|
||||||
file_name = "{domain}-urls-{uid}.txt".format(domain=domain, uid=uid)
|
file_name = f"{domain}-urls-{uid}.txt"
|
||||||
file_path = os.path.join(os.getcwd(), file_name)
|
file_path = os.path.join(os.getcwd(), file_name)
|
||||||
if not os.path.isfile(file_path):
|
if not os.path.isfile(file_path):
|
||||||
open(file_path, "w+").close()
|
open(file_path, "w+", encoding="utf-8").close()
|
||||||
|
|
||||||
with open(file_path, "a") as f:
|
with open(file_path, "a", encoding="utf-8") as file:
|
||||||
f.write("{url}\n".format(url=url))
|
file.write(f"{url}\n")
|
||||||
|
|
||||||
click.echo(url)
|
click.echo(url)
|
||||||
|
|
||||||
@ -302,21 +302,6 @@ def main( # pylint: disable=no-value-for-parameter
|
|||||||
elif url is None:
|
elif url is None:
|
||||||
click.echo("No URL detected. Please provide an URL.", err=True)
|
click.echo("No URL detected. Please provide an URL.", err=True)
|
||||||
|
|
||||||
elif (
|
|
||||||
not version
|
|
||||||
and not oldest
|
|
||||||
and not newest
|
|
||||||
and not near
|
|
||||||
and not save
|
|
||||||
and not known_urls
|
|
||||||
and not cdx
|
|
||||||
):
|
|
||||||
click.echo(
|
|
||||||
"Only URL passed, but did not specify what to do with the URL. "
|
|
||||||
"Use --help flag for help using waybackpy.",
|
|
||||||
err=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
elif oldest:
|
elif oldest:
|
||||||
availability_api = WaybackMachineAvailabilityAPI(url, user_agent=user_agent)
|
availability_api = WaybackMachineAvailabilityAPI(url, user_agent=user_agent)
|
||||||
availability_api.oldest()
|
availability_api.oldest()
|
||||||
@ -413,6 +398,13 @@ def main( # pylint: disable=no-value-for-parameter
|
|||||||
|
|
||||||
click.echo(" ".join(output_string))
|
click.echo(" ".join(output_string))
|
||||||
|
|
||||||
|
else:
|
||||||
|
click.echo(
|
||||||
|
"Only URL passed, but did not specify what to do with the URL. "
|
||||||
|
"Use --help flag for help using waybackpy.",
|
||||||
|
err=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main() # pylint: disable=no-value-for-parameter
|
main() # pylint: disable=no-value-for-parameter
|
||||||
|
Loading…
Reference in New Issue
Block a user