text
stringlengths
0
1.47k
# ===== file: skills/geo-sleuth/scripts/_net.py =====
"""HTTP helpers shared by service clients."""
from __future__ import annotations
import os
import subprocess
PROXY_HELP = "proxy URL or 'direct'"
def resolve_proxy(proxy: str | None = None) -> str | None:
value = (os.environ.get("GEO_PROXY", "") if proxy is None else proxy).strip()
return None if value.lower() in ("", "direct") else value
def curl_args(proxy: str | None = None) -> list[str]:
value = resolve_proxy(proxy)
# Clear NO_PROXY for an explicit proxy; ignore ambient proxies for direct mode.
return ["--proxy", value, "--noproxy", ""] if value else ["--noproxy", "*"]
def fetch_bytes(url: str, proxy: str | None = None, timeout: int = 20,
headers: dict[str, str] | None = None) -> bytes:
cmd = ["curl", "-q", "-fsSL", "--max-time", str(timeout), *curl_args(proxy)]
for name, value in (headers or {}).items():
cmd += ["-H", f"{name}: {value}"]
result = subprocess.run(cmd + [url], capture_output=True, timeout=timeout + 5)
if result.returncode:
raise RuntimeError(f"Request failed (curl exit {result.returncode}); run doctor.py --network to check connectivity.")
return result.stdout
def model_proxy_env(proxy: str | None = None) -> None:
"""Set the model downloader's process environment before importing its HTTP client."""
value = resolve_proxy(proxy)
for key in ("HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY",
"http_proxy", "https_proxy", "all_proxy", "no_proxy"):
os.environ.pop(key, None)
if value:
os.environ.update(HTTP_PROXY=value, HTTPS_PROXY=value, ALL_PROXY=value)
else:
os.environ["NO_PROXY"] = "*"
# ===== file: skills/geo-sleuth/scripts/baidu_pano.py =====
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.10"
# dependencies = ["pillow"]
# ///
"""Baidu panoramas (street view in China): find points, scan an area, render by heading, build comparison sheets.
Uses the public endpoints the Baidu Maps web page itself calls; no key needed.
The endpoints are rate-limited: when scanning an area, keep the step at 15 m or more and concurrency at 32 or less.
Baidu street view in China was mostly captured in 2017–2019; when comparing, look at old buildings, new ones may not be there yet.
Examples:
baidu_pano.py near 22.6047,114.0523 # nearest panorama point
baidu_pano.py info 09005700121709201230455178V # date, position, all points on this road
baidu_pano.py scan 22.6050,114.0535 --radius 300 --out panos.json
baidu_pano.py render 09005700121709201230455178V --heading 47 --out v.jpg
baidu_pano.py sheet --panos panos.json --toward 22.6072,114.0564 --offset -12 --out s.jpg
baidu_pano.py sheet --ids ID1,ID2 --heading 45 --out s.jpg
baidu_pano.py sheet --ids ID1 --headings 0,60,120,180,240,300 --out around.jpg # look around from a single point
baidu_pano.py sheet --panos panos.json --road <name>路 --spread 60 --toward 22.6072,114.0564 --out s.jpg # one road only (路 = road), thinned
baidu_pano.py sample --bbox 22.52,113.90,22.60,114.10 --n 24 --out cityA.jpg # street-view sample of a candidate city: compare guardrails, streetlights, bus stops
"""
from __future__ import annotations
import argparse
from _net import fetch_bytes, PROXY_HELP
import io
import json
import math
import os
import re
import sys
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
sys.path.insert(0, str(Path(__file__).parent))
import geo # noqa: E402
API = "https://mapsv0.bdimg.com/"
def _get(url: str, timeout: int = 20, proxy: str | None = None) -> bytes:
return fetch_bytes(url, proxy, timeout)
def near_bdmc(x: float, y: float, proxy: str | None = None) -> dict | None:
try:
c = json.loads(_get(f"{API}?qt=qsdata&x={x:.0f}&y={y:.0f}", proxy=proxy)).get("content")
except Exception:
return None
if not c:
return None
bx, by = c["x"] / 100, c["y"] / 100