2021-03-20 16:38:00 +00:00
|
|
|
__package__ = 'archivebox.parsers'
|
|
|
|
__description__ = 'URL list'
|
|
|
|
|
2021-04-01 07:31:55 +00:00
|
|
|
import re
|
|
|
|
|
2021-03-20 16:38:00 +00:00
|
|
|
from typing import IO, Iterable
|
2021-04-10 08:19:30 +00:00
|
|
|
from datetime import datetime, timezone
|
2021-03-20 16:38:00 +00:00
|
|
|
|
|
|
|
from ..index.schema import Link
|
2024-10-01 00:25:15 +00:00
|
|
|
from archivebox.misc.util import (
|
2021-04-01 07:31:55 +00:00
|
|
|
enforce_types,
|
|
|
|
URL_REGEX,
|
2021-03-20 16:38:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@enforce_types
|
|
|
|
def parse_url_list(text_file: IO[str], **_kwargs) -> Iterable[Link]:
|
|
|
|
"""Parse raw URLs from each line in a text file"""
|
|
|
|
|
|
|
|
text_file.seek(0)
|
|
|
|
for line in text_file.readlines():
|
|
|
|
url = line.strip()
|
2021-04-01 07:31:55 +00:00
|
|
|
if (not url) or not re.findall(URL_REGEX, url):
|
2021-03-20 16:38:00 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
yield Link(
|
|
|
|
url=url,
|
2021-04-10 08:19:30 +00:00
|
|
|
timestamp=str(datetime.now(timezone.utc).timestamp()),
|
2021-03-20 16:38:00 +00:00
|
|
|
title=None,
|
|
|
|
tags=None,
|
|
|
|
sources=[text_file.name],
|
|
|
|
)
|
2021-03-31 05:05:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
KEY = 'url_list'
|
|
|
|
NAME = 'URL List'
|
|
|
|
PARSER = parse_url_list
|