#!/usr/bin/env python3 """ CLI to query TLD prices from database """ import sys from db import get_prices, get_exchange_rate, init_db def show_prices(filter_tld: str = None, limit: int = 30): """Display TLD prices""" init_db() prices = get_prices() rate = get_exchange_rate() if not prices: print("No prices in database. Run update_prices.py first.") return if filter_tld: prices = [p for p in prices if filter_tld.lower() in p["tld"].lower()] print(f"Exchange rate: $1 = ₩{rate:,.0f}") print(f"{'TLD':12} {'USD':>8} {'KRW':>10}") print("-" * 32) for p in prices[:limit]: print(f".{p['tld']:11} ${p['usd']:7.2f} {p['krw']:>9,}원") if len(prices) > limit: print(f"\n... and {len(prices) - limit} more") def main(): if len(sys.argv) > 1: filter_tld = sys.argv[1] show_prices(filter_tld, limit=100) else: show_prices() if __name__ == "__main__": main()