"""Read-only check against Dropstar's real Correios contract, run by hand. A quote creates no shipment and costs nothing. python -m app.correios_probe [--cep 01310100 ...] [--peso 0.5 ...] It answers whether the user, access code and posting card are accepted (and which contract and DR the token carries), whether the contract prices PAC and SEDEX with the codes in use, and what they cost and take for one box (the JADLOG_CAIXA_CM sides) to a few regions. The first failure stops the run: an account problem would repeat on every line. In production, from the worker's console (Portainer > Containers > worker > Console), with CORREIOS_CODIGO_ACESSO in the stack: python -m app.correios_probe """ import argparse import os import sys from decimal import Decimal from .core.secrets import load as load_secret_files from .correios import SERVICES, CorreiosError, CorreiosQuotes from .package import box_cm DESTINATIONS = {'01310100': 'São Paulo', '20040002': 'Rio de Janeiro', '80010000': 'Curitiba', '50030230': 'Recife', '69005010': 'Manaus'} WEIGHTS = ['0.5', '2', '5'] def money(cents): return f'R$ {cents / 100:.2f}'.replace('.', ',') def run(quotes, sides, ceps, weights, out): try: quotes.bearer() except CorreiosError as error: out(f'ERRO no token: {error}') return 1 out(f'Token ok · cartão {quotes.card} · contrato {quotes.contract or "-"} · DR {quotes.dr or "-"} ' f'· válido até {quotes.expires:%d/%m %H:%M}') out(f"Origem {quotes.origin} · caixa {' × '.join(str(side) for side in sides)} cm") for service, (setting, default, label) in SERVICES.items(): code = (os.environ.get(setting) or default).strip() for cep in ceps: try: days = quotes.days(code, cep) for weight in weights: cents = quotes.price(code, cep, int(Decimal(weight) * 1000), sides) out(f"{label} ({code})\t{weight} kg\t{cep}\t{DESTINATIONS.get(cep, '')}\t{money(cents)}\t" f"{days if days is not None else '?'} dia(s)") except CorreiosError as error: out(f'ERRO {label} ({code}) para {cep}: {error}') return 1 return 0 def main(argv=None): parser = argparse.ArgumentParser(prog='python -m app.correios_probe') parser.add_argument('--cep', action='append', help='destination CEP (repeatable)') parser.add_argument('--peso', action='append', help='weight in kg (repeatable)') args = parser.parse_args(argv) load_secret_files() sides = box_cm(os.environ.get('JADLOG_CAIXA_CM') or '63x15.5x15.5') return run(CorreiosQuotes(), sides, args.cep or list(DESTINATIONS), args.peso or WEIGHTS, print) if __name__ == '__main__': sys.exit(main())