{"repo": "alanfeng99/minimax-image-30-days-job", "files": {"daily_run.py": {"f9c92099846e02631b3b7ef4a959ac028ffb573a": {"t": 1785674011.270482, "n": 4074, "h": "1328c8d8b6733b76", "c": "#!/usr/bin/env python3\nimport json, subprocess, os, sys, time, shutil\n\nBASE_DIR = os.path.expanduser(\"~/.openclaw/workspace/monthly-minimax-image/30day\")\nSTATE_FILE = os.path.join(BASE_DIR, \".current_day\")\nPROMPTS_JSON = os.path.expanduser(\"~/.openclaw/workspace/monthly-minimax-image/29day_prompts.json\")\nLOG_FILE = os.path.join(BASE_DIR, \"daily_run.log\")\nTEMP_DIR = \"/tmp/minimax_gen\"\n\nAPI_KEY = \"sk-cp-TunEis7pOTrjuKDkn-DT64fRl94QKm-TfIMGTcpzp9HZbOr5lh_1Df3DYQBUDUrEmkdZTfwpoBw0gXASqU7yOPO6wgtxCzqqbdsrtSgiJb_fXBb_TawBygU\"\nENDPOINT = \"https://api.minimax.io/v1/image_generation\"\n\nos.makedirs(BASE_DIR, exist_ok=True)\nos.makedirs(TEMP_DIR, exist_ok=True)\n\nwith open(STATE_FILE) as f:\n lines = f.read().strip().split('\\n')\nCURRENT_DAY = int(lines[0].strip())\nts = time.strftime('%Y-%m-%d %H:%M:%S')\n\nlog = f\"[{ts}] Starting Day {CURRENT_DAY}\\n\"\nprint(log)\n\ndata = json.load(open(PROMPTS_JSON))\nprompts = sorted([p for p in data if p['day'] == CURRENT_DAY], key=lambda x: x['index'])\nprint(f\"Found {len(prompts)} prompts for Day {CURRENT_DAY}\")\n\nif not prompts:\n print(f\"No prompts defined for Day {CURRENT_DAY} — skipping. Define theme manually.\")\n sys.exit(0)\n\nDAY_DIR = os.path.join(BASE_DIR, f\"day-{CURRENT_DAY:02d}\")\nos.makedirs(DAY_DIR, exist_ok=True)\n\nok_count = 0\nfail_count = 0\n\nfor p in prompts:\n idx = p['index']\n filename = p['filename']\n OUTPUT_FILE = os.path.join(DAY_DIR, filename)\n payload_file = os.path.join(TEMP_DIR, f\"task_{idx:02d}.json\")\n resp_file = os.path.join(TEMP_DIR, f\"resp_{idx:02d}.json\")\n \n payload = {\"model\": \"image-01\", \"prompt\": p['prompt'], \"image_size\": p['aspect'], \"num_images\": 1}\n with open(payload_file, 'w') as f:\n json.dump(payload, f)\n \n start = time.time()\n result = subprocess.run([\n 'curl', '-s', '-o', resp_file, '-w', '%{http_code}',\n '--max-time', '120',\n '-H', 'Authorization: Bearer ' + API_KEY,\n '-H', 'Content-Type: application/json',\n '--data-binary', '@' + payload_file,\n ENDPOINT\n ], capture_output=True, text=True)\n \n http_code = result.stdout.strip()\n duration = time.time() - start\n \n if http_code == '200':\n try:\n resp_data = json.load(open(resp_file))\n urls = resp_data.get('data', {}).get('image_urls', [])\n image_url = urls[0] if urls else ''\n if image_url:\n subprocess.run(['curl', '-s', '--max-time', '60', '-o', OUTPUT_FILE, image_url], check=True)\n size = os.path.getsize(OUTPUT_FILE)\n log_line = f\"[{idx}/50] OK {duration:.1f}s size={size}B | {filename}\\n\"\n print(f\"[{idx}/50] OK {duration:.1f}s | {filename}\")\n ok_count += 1\n else:\n err = resp_data.get('base_resp', {}).get('status_msg', 'no_url')\n log_line = f\"[{idx}/50] FAIL | {err}\\n\"\n print(f\"[{idx}/50] FAIL | {err}\")\n fail_count += 1\n except Exception as e:\n log_line = f\"[{idx}/50] FAIL | {str(e)[:100]}\\n\"\n fail_count += 1\n else:\n try:\n resp_data = json.load(open(resp_file))\n err = resp_data.get('base_resp', {}).get('status_msg', 'http_' + http_code)\n except:\n err = 'http_' + http_code\n log_line = f\"[{idx}/50] FAIL HTTP {http_code} | {err}\\n\"\n print(f\"[{idx}/50] FAIL HTTP {http_code} | {err}\")\n fail_count += 1\n \n with open(LOG_FILE, 'a') as f:\n f.write(log_line)\n \n time.sleep(3)\n if idx % 5 == 0:\n time.sleep(5)\n\nnext_day = CURRENT_DAY + 1\nif next_day > 29:\n next_day = 1\n\nwith open(STATE_FILE, 'w') as f:\n f.write(f\"{next_day}\\n{time.strftime('%Y-%m-%d %H:%M:%S')}\\nDay {CURRENT_DAY}: {ok_count} OK, {fail_count} FAIL\\n\")\n\nwith open(LOG_FILE, 'a') as f:\n f.write(f\"\\n[{time.strftime('%Y-%m-%d %H:%M:%S')}] Day {CURRENT_DAY} COMPLETE -- OK: {ok_count} | FAIL: {fail_count}\\n\")\n\nprint(f\"Done: Day {CURRENT_DAY} -- {ok_count} OK, {fail_count} FAIL\")\nshutil.rmtree(TEMP_DIR, ignore_errors=True)\n"}}}}