Hunting Political Debt in the Terminal: Inside cuantodeben_plot

How a solo developer built an OSINT pipeline to scrape, normalize, and expose the hidden financial liabilities of Argentine public officials.

6 min read • View on GitHub • More from rquiroga7

A tangled web of paper ledgers fed into a machine that outputs a straight line of ticker tape, representing the normalization of chaotic financial data.
cuantodeben_plot acts as a forensic sorting mechanism, isolating signal from chaotic, unstructured government data.
Key Takeaways

The Mathematical Signature of Leverage

Most data visualization tools assume the data wants to be seen. cuantodeben_plot assumes the opposite. Built to audit the financial disclosures of Argentine politicians, legislators, and judicial members, the repository functions less like a plotting library and more like an automated investigative journalist.

The core logic inside analyze_debts.py operates on a simple premise: public officials often hide massive liabilities by shifting them to relatives. Instead of merely parsing a primary subject's debt, the extract_max_debt_per_person function recursively traverses a familiares array. It hunts for the mathematical signature of leverage across an entire household.

A close-up of a magnifying glass over a ledger, where a crossed-out name is connected by a taut thread to a secondary name in the margin, illustrating recursive family debt tracking.
The pipeline traverses household graphs, ensuring that debt shifted to family members triggers the same forensic alerts as direct liabilities.

Once the household debt is aggregated, plot_debts.py applies a change-detection algorithm. It calculates month-over-month deltas. If a sudden spike exceeds a hardcoded 50 million ARS threshold, the system flags a "Loan Event," merging temporally proximate spikes to avoid double-counting refinanced loans.

Scraping a Hostile DOM

Extracting this data from the Banco de la Nación Argentina requires a multi-tiered offensive. Standard scraping pipelines rely on predictable CSS selectors. When targeting state-run Single Page Applications (SPAs) that actively resist automated extraction, that approach fails.

The ingestion layer splits the difference. scrape_debts.py attempts a fast, lightweight extraction using raw requests, hunting for embedded JSON within script tags using aggressive regex patterns like r'\[.*\]|\{.*\}'. When the DOM proves too dynamic, it falls back to a headless Selenium driver.

def extract_amount(text):
    # Heuristic to handle Argentine currency formatting
    cleaned = text.replace('.', '').replace(',', '.')
    if 'M' in cleaned:
        return float(cleaned.replace('M', '')) * 1000000
    return float(cleaned)

Even with Selenium, the script relies on fuzzy keyword heuristics—searching for elements containing ['deuda', 'banco', 'nación']—rather than strict structural paths. It then normalizes the idiosyncratic Argentine currency formatting, converting "M" suffixes into clean floats ready for analysis.

The Hyperinflation Variable

Tracking wealth in Argentina carries an implicit, massive variable: hyperinflation. A nominal increase in debt might simply reflect the eroding value of the currency rather than new, potentially illicit leverage. To combat this, the pipeline integrates Consumer Price Index (IPC) data.

Adjusting for inflation separates nominal currency erosion from the deliberate acquisition of massive new debt.

By differentiating between real and nominal debt, the tool ensures that its algorithmic triggers only fire when a public official is actually acquiring new capital, effectively filtering out the baseline noise of the Argentine economy.

OSINT Forensics vs. Standard Analytics

It is tempting to view cuantodeben_plot as just another Matplotlib wrapper. In reality, it represents a fundamental shift from standard data engineering to investigative data journalism.

FeatureStandard Analytics PipelineOSINT Forensic Pipeline
TargetingDirect subject analysisRecursive graph traversal of relatives
ExtractionFixed CSS selectors & APIsFuzzy keyword heuristics & DOM fallback
MetricsAbsolute valuesInflation-adjusted, threshold-based deltas

By codifying journalistic intuition into reproducible Python scripts, the project democratizes financial oversight. It proves that with the right heuristics, a solo developer can build an automated auditing engine capable of piercing opaque institutional veils.

Portrait of rquiroga7 in a stippled, WSJ hedcut style.