Skip to content

Commit 1216ffb

Browse files
committed
lint and refactor cli module
1 parent d58a5f0 commit 1216ffb

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

waybackpy/cli.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ def save_urls_on_file(url_gen: Generator[str, None, None]) -> None:
5959
for url in url_gen:
6060
url_count += 1
6161
if not domain:
62-
m = re.search("https?://([A-Za-z_0-9.-]+).*", url)
62+
match = re.search("https?://([A-Za-z_0-9.-]+).*", url)
6363

6464
domain = "domain-unknown"
6565

66-
if m:
67-
domain = m.group(1)
66+
if match:
67+
domain = match.group(1)
6868

69-
file_name = "{domain}-urls-{uid}.txt".format(domain=domain, uid=uid)
69+
file_name = f"{domain}-urls-{uid}.txt"
7070
file_path = os.path.join(os.getcwd(), file_name)
7171
if not os.path.isfile(file_path):
72-
open(file_path, "w+").close()
72+
open(file_path, "w+", encoding="utf-8").close()
7373

74-
with open(file_path, "a") as f:
75-
f.write("{url}\n".format(url=url))
74+
with open(file_path, "a", encoding="utf-8") as file:
75+
file.write(f"{url}\n")
7676

7777
click.echo(url)
7878

@@ -302,21 +302,6 @@ def main( # pylint: disable=no-value-for-parameter
302302
elif url is None:
303303
click.echo("No URL detected. Please provide an URL.", err=True)
304304

305-
elif (
306-
not version
307-
and not oldest
308-
and not newest
309-
and not near
310-
and not save
311-
and not known_urls
312-
and not cdx
313-
):
314-
click.echo(
315-
"Only URL passed, but did not specify what to do with the URL. "
316-
"Use --help flag for help using waybackpy.",
317-
err=True,
318-
)
319-
320305
elif oldest:
321306
availability_api = WaybackMachineAvailabilityAPI(url, user_agent=user_agent)
322307
availability_api.oldest()
@@ -413,6 +398,13 @@ def main( # pylint: disable=no-value-for-parameter
413398

414399
click.echo(" ".join(output_string))
415400

401+
else:
402+
click.echo(
403+
"Only URL passed, but did not specify what to do with the URL. "
404+
"Use --help flag for help using waybackpy.",
405+
err=True,
406+
)
407+
416408

417409
if __name__ == "__main__":
418410
main() # pylint: disable=no-value-for-parameter

0 commit comments

Comments
 (0)