Pulls real player-posted freight jobs from FIO's /localmarket/shipping endpoints (public, no auth - distinct from the CONTD player-contract system, which isn't exposed via any API). Ranks by margin after real one-way fuel cost (puga.shipping.leg_cost), flagging ads that exceed the account's ship hold or route through an unmeasured gateway. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
46 lines
2.3 KiB
Python
46 lines
2.3 KiB
Python
"""Public FIO REST (rest.fnar.net). Static game data caches long; market data short."""
|
|
from .cache import get_json
|
|
|
|
BASE = "https://rest.fnar.net"
|
|
STATIC, MARKET = 24 * 3600, 15 * 60
|
|
|
|
|
|
def _g(path: str, ttl: int, refresh: bool = False):
|
|
return get_json(BASE + path, ttl, refresh=refresh)
|
|
|
|
|
|
def exchange_all(refresh=False): return _g("/exchange/all", MARKET, refresh)
|
|
def order_book(mat: str, cx: str, refresh=False):
|
|
"""Full book: BuyingOrders / SellingOrders lists (price + quantity). Short TTL."""
|
|
return _g(f"/exchange/{mat}.{cx}", 5 * 60, refresh)
|
|
def cxpc(mat: str, cx: str, refresh=False):
|
|
return _g(f"/exchange/cxpc/{mat}.{cx}", 3600, refresh)
|
|
def materials(refresh=False): return _g("/material/allmaterials", STATIC, refresh)
|
|
def recipes(refresh=False): return _g("/recipes/allrecipes", STATIC, refresh)
|
|
def buildings(refresh=False): return _g("/building/allbuildings", STATIC, refresh)
|
|
def planets_full(refresh=False): return _g("/planet/allplanets/full", STATIC, refresh)
|
|
def workforce_needs(refresh=False): return _g("/global/workforceneeds", STATIC, refresh)
|
|
def systems(refresh=False): return _g("/systemstars", STATIC, refresh)
|
|
def stations(refresh=False): return _g("/exchange/station", STATIC, refresh)
|
|
def lm_shipping_source(planet: str, refresh=False):
|
|
"""Live Local Market hauling ads where `planet` is the pickup - public, no auth needed."""
|
|
return _g(f"/localmarket/shipping/source/{planet}", 15 * 60, refresh)
|
|
def lm_shipping_destination(planet: str, refresh=False):
|
|
"""Live Local Market hauling ads where `planet` is the drop-off - public, no auth needed."""
|
|
return _g(f"/localmarket/shipping/destination/{planet}", 15 * 60, refresh)
|
|
|
|
|
|
def own(path: str, ttl: int = 300, refresh: bool = False):
|
|
"""Authenticated FIO REST (own data: /sites/{user}, /storage/{user}, /production/{user}, /ship/ships/{user}...).
|
|
Auth: `Authorization: <FIO_REST_KEY>` (verified 2026-09-18). FIO_API_KEY does NOT work on rest.fnar.net."""
|
|
from . import config
|
|
key = config.get("FIO_REST_KEY")
|
|
if not key:
|
|
raise RuntimeError("FIO_REST_KEY missing in .env")
|
|
return get_json(BASE + path, ttl, headers={"Authorization": key}, refresh=refresh)
|
|
|
|
|
|
def me() -> str:
|
|
from . import config
|
|
return config.get("FIO_USERNAME", "")
|