mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
import csv
|
|
import ast
|
|
import re
|
|
import json
|
|
import boto3
|
|
from backend.app.db.models.tasks import SourceEnum
|
|
from backend.app.db.functions.tasks.Tasks import TasksInterface
|
|
|
|
SQS_QUEUE_URL = "https://sqs.eu-west-2.amazonaws.com/337213553626/model-engine-queue"
|
|
file_path = "/Users/khalimconn-kowlessar/Downloads/assessment-model-log-export-2026-04-21T19-57-35.csv"
|
|
|
|
payloads = []
|
|
|
|
|
|
def clean_js_object(js_str):
|
|
# Extract object after "Triggering plan with body:"
|
|
match = re.search(r"Triggering plan with body:\s*(\{.*\})", js_str, re.DOTALL)
|
|
if not match:
|
|
return None
|
|
|
|
obj = match.group(1)
|
|
|
|
# Convert JS → Python
|
|
obj = re.sub(r"(\w+):", r'"\1":', obj) # quote keys
|
|
obj = obj.replace("true", "True")
|
|
obj = obj.replace("false", "False")
|
|
obj = obj.replace("null", "None")
|
|
|
|
return obj
|
|
|
|
|
|
with open(file_path, newline='', encoding='utf-8') as csvfile:
|
|
reader = csv.DictReader(csvfile)
|
|
|
|
for row in reader:
|
|
message = row.get("message", "")
|
|
|
|
if "Triggering plan with body:" in message:
|
|
cleaned = clean_js_object(message)
|
|
if cleaned:
|
|
try:
|
|
payload = ast.literal_eval(cleaned)
|
|
payloads.append(payload)
|
|
except Exception as e:
|
|
print("Failed to parse:", e)
|
|
|
|
# Print ready-to-copy output
|
|
print("payloads = [")
|
|
for p in payloads:
|
|
print(f" {p},")
|
|
print("]")
|
|
|
|
# For this, we don't retrigger portfolio 685 since that was internal
|
|
payloads_to_retrigger = [x for x in payloads if x["portfolio_id"] != "685"]
|
|
|
|
sqs_client = boto3.client("sqs")
|
|
|
|
# Re-trigger:
|
|
for payload in payloads_to_retrigger:
|
|
task_id, subtask_id = TasksInterface.create_task(
|
|
task_source="backend/plan/router.py:trigger_plan_entrypoint",
|
|
service="plan_engine",
|
|
inputs=payload,
|
|
task_only=False,
|
|
source=SourceEnum.PORTFOLIO,
|
|
source_id=str(payload["portfolio_id"]),
|
|
)
|
|
payload["task_id"] = str(task_id)
|
|
payload["subtask_id"] = str(subtask_id)
|
|
message_body = json.dumps(payload)
|
|
response = sqs_client.send_message(
|
|
QueueUrl=SQS_QUEUE_URL, MessageBody=message_body
|
|
)
|
|
print(f"SQS message sent. Message ID: {response.get('MessageId')}")
|