""" Simulated social-media feed for CIRO demos. Why simulated ------------- The hackathon scope (see OUT_OF_SCOPE.md) explicitly rules out live scraping of Twitter/X, Facebook, etc. Real demos need reproducible input, so we ship a small catalogue of pre-written Urdu/English posts keyed by named scenario. Each scenario bundles: • a stable `location_label` and `coordinates` (so every signal in the scenario plausibly comes from the same area), • a fixed `signal_type` and source-level `severity_hint`, • a list of `posts` — natural-language strings exactly as a user would post them. Adding a scenario is the *only* way new social-media-style content enters the system. There is no scraping, no live feed, no third-party client. """ from __future__ import annotations from datetime import datetime, timezone from typing import TypedDict from backend.models.signal import ( TRUST_WEIGHT_SOCIAL_MEDIA, CrisisSignal, SeverityHint, SignalType, ) class _Scenario(TypedDict): location_label: str coordinates: tuple[float, float] signal_type: SignalType severity_hint: SeverityHint | None posts: list[str] # Coordinates are deliberately approximate — exact-enough to drop a marker # in the right sector on a map without claiming sub-block precision. SCENARIOS: dict[str, _Scenario] = { "g10_flood": { "location_label": "G-10, Islamabad", "coordinates": (33.6844, 73.0479), "signal_type": "flood", "severity_hint": "heavy", "posts": [ "G-10 mein pani bhar gaya hai, gaariyan phans gayi hain", "Flash flood on main G-10 road, cars stuck", "Yahan pani itna zyada hai, nikal nahi saktay", ], }, "g18_fire": { "location_label": "G-18, Islamabad", "coordinates": (33.6093, 72.9213), "signal_type": "fire", "severity_hint": "heavy", "posts": [ "G-18 mein aag lag gayi hai", "Huge fire near G-18 markaz, smoke visible from far", "Fire brigade ko bulao, G-18 main road", ], }, "i8_traffic": { "location_label": "I-8 Flyover, Islamabad", "coordinates": (33.6663, 73.0723), "signal_type": "traffic", "severity_hint": "moderate", "posts": [ "I-8 flyover completely jammed, no movement for 40 mins", "Bohat zyada traffic hai I-8 par, koi accident hua lagta hai", ], }, } def list_scenarios() -> list[str]: """Return the ids of every available demo scenario.""" return list(SCENARIOS.keys()) def get_social_feed(scenario: str) -> list[CrisisSignal]: """Return all social-media signals for a named demo scenario. Args: scenario: One of the keys in `SCENARIOS` (e.g. `"g10_flood"`). Returns: A list of `CrisisSignal` instances with `source="social_media"` and `trust_weight=0.5`, one per pre-written post. Returns `[]` for unknown scenarios — callers treat that the same way they treat a real-world feed with no matching posts. """ bundle = SCENARIOS.get(scenario) if bundle is None: return [] now = datetime.now(timezone.utc) return [ CrisisSignal( source="social_media", trust_weight=TRUST_WEIGHT_SOCIAL_MEDIA, raw_text=post, location_label=bundle["location_label"], coordinates=bundle["coordinates"], signal_type=bundle["signal_type"], severity_hint=bundle["severity_hint"], timestamp=now, ) for post in bundle["posts"] ]