-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_regex_final.py
More file actions
43 lines (36 loc) · 1.39 KB
/
fix_regex_final.py
File metadata and controls
43 lines (36 loc) · 1.39 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
files = [
'backend/ai_module/gapgpt_client.py',
'backend/ai_module/providers/__init__.py',
'backend/ai_module/provider_manager.py'
]
# الگوهای دقیق که در فایل هستند
old_patterns = [
r"(?:remain|remaining)[\s_]?quota[::\s]*\$?\??([\d.]+)",
r"need[\s_]?quota[::\s]*\$?\??([\d.]+)"
]
new_patterns = [
r'(?:remain|remaining)\s+quota[::\s]*\s*\??([\d.]+)',
r'need\s+quota[::\s]*\s*\??([\d.]+)'
]
for file_path in files:
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
original_content = content
# جایگزینی الگوها
for old, new in zip(old_patterns, new_patterns):
# در raw string Python، باید backslash ها را escape کنیم
old_in_file = f"r'{old}'"
new_in_file = f"r'{new}'"
content = content.replace(old_in_file, new_in_file)
# اگر تغییری ایجاد شد، فایل را ذخیره کن
if content != original_content:
with open(file_path, 'w', encoding='utf-8') as f:
f.write(content)
print(f'✓ Updated {file_path}')
else:
print(f'- No changes needed in {file_path}')
except Exception as e:
print(f'✗ Error processing {file_path}: {e}')