feat: add RF4MAP and RF4 Posts research parsers
This commit is contained in:
@@ -6,7 +6,13 @@ import sys
|
||||
from dataclasses import asdict
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
from .community_sources import parse_rf4db_catches, parse_rf4stat_fishing, parse_rf4stat_posts
|
||||
from .community_sources import (
|
||||
parse_rf4db_catches,
|
||||
parse_rf4map_point,
|
||||
parse_rf4posts_spot,
|
||||
parse_rf4stat_fishing,
|
||||
parse_rf4stat_posts,
|
||||
)
|
||||
|
||||
|
||||
SOURCES = {
|
||||
@@ -14,6 +20,10 @@ SOURCES = {
|
||||
"rf4stat-fishing": ("https://rf4-stat.ru/fishing/", parse_rf4stat_fishing),
|
||||
"rf4stat-posts": ("https://rf4-stat.ru/posts/", parse_rf4stat_posts),
|
||||
}
|
||||
DETAIL_SOURCES = {
|
||||
"rf4map-point": parse_rf4map_point,
|
||||
"rf4posts-spot": parse_rf4posts_spot,
|
||||
}
|
||||
USER_AGENT = "RF4-Spotter/0.1 (authorized data integration)"
|
||||
|
||||
|
||||
@@ -27,14 +37,17 @@ def fetch_html(url: str, *, timeout: float = 30) -> str:
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser(description="Fetch one authorized RF4 community source page")
|
||||
parser.add_argument("source", choices=SOURCES)
|
||||
parser.add_argument("source", choices=(*SOURCES, *DETAIL_SOURCES))
|
||||
parser.add_argument("--url", help="Override the configured public page URL")
|
||||
parser.add_argument("--limit", type=int, default=100, choices=range(1, 501), metavar="1..500")
|
||||
args = parser.parse_args(argv)
|
||||
default_url, parse = SOURCES[args.source]
|
||||
if args.source in DETAIL_SOURCES and not args.url:
|
||||
parser.error(f"--url is required for {args.source}")
|
||||
default_url, parse = SOURCES.get(args.source, (None, DETAIL_SOURCES.get(args.source)))
|
||||
url = args.url or default_url
|
||||
try:
|
||||
records = parse(fetch_html(url))[:args.limit]
|
||||
html = fetch_html(url)
|
||||
records = (parse(html, source_url=url) if args.source in DETAIL_SOURCES else parse(html))[:args.limit]
|
||||
except Exception as exc:
|
||||
print(f"community source failed: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user