()
| 21815 | |
| 21816 | @app.route('/api/social/watch', methods=['POST']) |
| 21817 | def api_social_watch_start(): |
| 21818 | payload = request.json or {} |
| 21819 | target = str(payload.get('target') or "").strip() |
| 21820 | platform = _normalize_instagram_platform(payload.get('platform')) |
| 21821 | if not platform: |
| 21822 | return jsonify({"error": "Supportata solo la piattaforma Instagram"}), 400 |
| 21823 | if not target: |
| 21824 | return jsonify({"error": "target mancante"}), 400 |
| 21825 | try: |
| 21826 | interval_seconds = max(5, int(payload.get('interval_seconds') or payload.get('interval', 300))) |
| 21827 | except Exception: |
| 21828 | interval_seconds = 300 |
| 21829 | try: |
| 21830 | iterations = int(payload.get('iterations') or 0) |
| 21831 | except Exception: |
| 21832 | iterations = 0 |
| 21833 | watch_id = uuid.uuid4().hex |
| 21834 | now = datetime.now(timezone.utc).isoformat() |
| 21835 | watch = { |
| 21836 | "watch_id": watch_id, |
| 21837 | "target": target, |
| 21838 | "platform": platform, |
| 21839 | "interval_seconds": interval_seconds, |
| 21840 | "iterations": max(0, iterations), |
| 21841 | "iterations_done": 0, |
| 21842 | "events": [], |
| 21843 | "running": True, |
| 21844 | "status": "running", |
| 21845 | "created_at": now, |
| 21846 | "last_run_at": None, |
| 21847 | "last_snapshot_id": None, |
| 21848 | "last_error": None |
| 21849 | } |
| 21850 | with SOCIAL_WATCHES_LOCK: |
| 21851 | SOCIAL_WATCHES[watch_id] = watch |
| 21852 | threading.Thread( |
| 21853 | target=_social_watch_worker, |
| 21854 | args=(watch_id, target, platform, interval_seconds, max(0, iterations)), |
| 21855 | daemon=True |
| 21856 | ).start() |
| 21857 | return jsonify(watch) |
| 21858 | |
| 21859 | @app.route('/api/social/watch/<watch_id>', methods=['GET']) |
| 21860 | def api_social_watch_status(watch_id): |
nothing calls this directly
no test coverage detected