improve code quality, remove unused imports, use system randomness etc
This commit is contained in:
parent
d549d31421
commit
40233eb115
@ -95,8 +95,9 @@ def _save_urls_on_file(input_list, live_url_count):
|
|||||||
if m:
|
if m:
|
||||||
domain = m.group(1)
|
domain = m.group(1)
|
||||||
|
|
||||||
|
sys_random = random.SystemRandom()
|
||||||
uid = "".join(
|
uid = "".join(
|
||||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(6)
|
sys_random.choice(string.ascii_lowercase + string.digits) for _ in range(6)
|
||||||
)
|
)
|
||||||
|
|
||||||
file_name = "{domain}-{live_url_count}-urls-{uid}.txt".format(
|
file_name = "{domain}-{live_url_count}-urls-{uid}.txt".format(
|
||||||
|
@ -123,11 +123,11 @@ def _check_filters(filters):
|
|||||||
raise WaybackError("filters must be a list.")
|
raise WaybackError("filters must be a list.")
|
||||||
|
|
||||||
# [!]field:regex
|
# [!]field:regex
|
||||||
for filter in filters:
|
for _filter in filters:
|
||||||
try:
|
try:
|
||||||
match = re.search(
|
match = re.search(
|
||||||
r"(\!?(?:urlkey|timestamp|original|mimetype|statuscode|digest|length)):(.*)",
|
r"(\!?(?:urlkey|timestamp|original|mimetype|statuscode|digest|length)):(.*)",
|
||||||
filter,
|
_filter,
|
||||||
)
|
)
|
||||||
|
|
||||||
key = match.group(1)
|
key = match.group(1)
|
||||||
@ -135,8 +135,8 @@ def _check_filters(filters):
|
|||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
exc_message = (
|
exc_message = (
|
||||||
"Filter '{filter}' not following the cdx filter syntax.".format(
|
"Filter '{_filter}' not following the cdx filter syntax.".format(
|
||||||
filter=filter
|
_filter=_filter
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
raise WaybackError(exc_message)
|
raise WaybackError(exc_message)
|
||||||
@ -267,7 +267,7 @@ def _archive_url_parser(header, url, latest_version=__version__, instance=None):
|
|||||||
newest_archive = None
|
newest_archive = None
|
||||||
try:
|
try:
|
||||||
newest_archive = instance.newest()
|
newest_archive = instance.newest()
|
||||||
except Exception as e:
|
except WaybackError:
|
||||||
pass # We don't care as this is a save request
|
pass # We don't care as this is a save request
|
||||||
|
|
||||||
if newest_archive:
|
if newest_archive:
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import requests
|
|
||||||
import concurrent.futures
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user