-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_regex_lines.py
More file actions
78 lines (66 loc) · 2.42 KB
/
fix_regex_lines.py
File metadata and controls
78 lines (66 loc) · 2.42 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# خواندن فایل
with open('backend/ai_module/gapgpt_client.py', 'r', encoding='utf-8') as f:
lines = f.readlines()
# تغییر خط 775
if 'remaining)[\\s_]?quota' in lines[774]:
lines[774] = lines[774].replace(
r'[\s_]?quota[::\s]*\$?\??([\d.]+)',
r'\s+quota[::\s]*\s*\??([\d.]+)'
)
print("Fixed line 775")
# تغییر خط 776
if 'need[\\s_]?quota' in lines[775]:
lines[775] = lines[775].replace(
r'[\s_]?quota[::\s]*\$?\??([\d.]+)',
r'\s+quota[::\s]*\s*\??([\d.]+)'
)
print("Fixed line 776")
# تغییر خط 1333
if 'remaining)[\\s_]?quota' in lines[1332]:
lines[1332] = lines[1332].replace(
r'[\s_]?quota[::\s]*\$?\??([\d.]+)',
r'\s+quota[::\s]*\s*\??([\d.]+)'
)
print("Fixed line 1333")
# تغییر خط 1334
if 'need[\\s_]?quota' in lines[1333]:
lines[1333] = lines[1333].replace(
r'[\s_]?quota[::\s]*\$?\??([\d.]+)',
r'\s+quota[::\s]*\s*\??([\d.]+)'
)
print("Fixed line 1334")
# ذخیره فایل
with open('backend/ai_module/gapgpt_client.py', 'w', encoding='utf-8') as f:
f.writelines(lines)
print("Done with gapgpt_client.py")
# همین کار را برای فایلهای دیگر
for file_path in ['backend/ai_module/providers/__init__.py', 'backend/ai_module/provider_manager.py']:
with open(file_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
modified = False
for i, line in enumerate(lines):
if 'remaining)[\\s_]?quota' in line or 'remain)[\\s_]?quota' in line:
new_line = line.replace(
r'[\s_]?quota[::\s]*\$?\??([\d.]+)',
r'\s+quota[::\s]*\s*\??([\d.]+)'
)
if new_line != line:
lines[i] = new_line
modified = True
print(f"Fixed line {i+1} in {file_path}")
if 'need[\\s_]?quota' in line:
new_line = line.replace(
r'[\s_]?quota[::\s]*\$?\??([\d.]+)',
r'\s+quota[::\s]*\s*\??([\d.]+)'
)
if new_line != line:
lines[i] = new_line
modified = True
print(f"Fixed line {i+1} in {file_path}")
if modified:
with open(file_path, 'w', encoding='utf-8') as f:
f.writelines(lines)
print(f"Done with {file_path}")
print("All done!")