MCPcopy Create free account
hub / github.com/CScorza/IntelOSINT / _social_watch_worker

Function _social_watch_worker

IntelOSINT.py:21713–21763  ·  view source on GitHub ↗
(watch_id, target, platform, interval_seconds, iterations)

Source from the content-addressed store, hash-verified

21711 }
21712
21713def _social_watch_worker(watch_id, target, platform, interval_seconds, iterations):
21714 while True:
21715 with SOCIAL_WATCHES_LOCK:
21716 watch = SOCIAL_WATCHES.get(watch_id)
21717 if not watch or not watch.get("running"):
21718 break
21719 try:
21720 snapshot = core.social_snapshot(target, platform)
21721 history = core._read_social_snapshot_history(target, platform, limit=2)
21722 diff_payload = {}
21723 if len(history) >= 2:
21724 diff_payload = core._social_snapshot_diff(history[-2], history[-1])
21725 event = {
21726 "at": datetime.now(timezone.utc).isoformat(),
21727 "snapshot_id": snapshot.get("snapshot_id") if isinstance(snapshot, dict) else None,
21728 "diff": diff_payload,
21729 }
21730 with SOCIAL_WATCHES_LOCK:
21731 watch = SOCIAL_WATCHES.get(watch_id)
21732 if not watch:
21733 break
21734 watch["events"].append(event)
21735 if len(watch["events"]) > SOCIAL_WATCH_MAX_EVENTS:
21736 watch["events"] = watch["events"][-SOCIAL_WATCH_MAX_EVENTS:]
21737 watch["last_snapshot_id"] = event.get("snapshot_id")
21738 watch["last_run_at"] = event.get("at")
21739 if watch.get("running"):
21740 watch["iterations_done"] = watch.get("iterations_done", 0) + 1
21741 if iterations and watch.get("iterations_done", 0) >= iterations:
21742 watch["running"] = False
21743 watch["status"] = "completed"
21744 if not watch.get("running"):
21745 watch["status"] = "completed"
21746 except Exception as e:
21747 with SOCIAL_WATCHES_LOCK:
21748 watch = SOCIAL_WATCHES.get(watch_id)
21749 if not watch:
21750 break
21751 watch["status"] = "error"
21752 watch["last_error"] = str(e)
21753 if iterations:
21754 with SOCIAL_WATCHES_LOCK:
21755 watch = SOCIAL_WATCHES.get(watch_id)
21756 if watch and not watch.get("running"):
21757 return
21758 for _ in range(interval_seconds):
21759 with SOCIAL_WATCHES_LOCK:
21760 watch = SOCIAL_WATCHES.get(watch_id)
21761 if not watch or not watch.get("running"):
21762 return
21763 time.sleep(1)
21764
21765@app.route('/api/social/snapshot', methods=['POST'])
21766def api_social_snapshot():

Callers

nothing calls this directly

Calls 3

social_snapshotMethod · 0.80
_social_snapshot_diffMethod · 0.80

Tested by

no test coverage detected