Spaces:
Running
Running
File size: 1,196 Bytes
388ee0f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | with open('app/api/routes/analysis.py', 'r', encoding='utf-8') as f:
content = f.read()
import re
# We want to extract the two chat routes:
# @router.get('/{analysis_id}/chat', ...
# ... up to @router.post('/{analysis_id}/export/{format}')
chat_get_match = re.search(r'(@router\.get\(\"\/\{analysis_id\}\/chat\".*?)(?=@router\.post\(\"\/\{analysis_id\}\/export)', content, re.DOTALL)
if chat_get_match:
chat_code = chat_get_match.group(1)
# Remove it from the original content
content_without_chat = content.replace(chat_code, '')
# Insert it before get_specific_analysis
target = r'@router\.get\(\"\/\{project_id\}\/\{analysis_id\}\"'
target_match = re.search(target, content_without_chat)
if target_match:
insert_pos = target_match.start()
new_content = content_without_chat[:insert_pos] + chat_code + '\n' + content_without_chat[insert_pos:]
with open('app/api/routes/analysis.py', 'w', encoding='utf-8') as f:
f.write(new_content)
print('SUCCESS: Moved chat routes above get_specific_analysis')
else:
print('ERROR: target not found')
else:
print('ERROR: chat routes not found')
|