Upload github强制换源.py
Browse files- github强制换源.py +25 -0
github强制换源.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
def replace_links_in_file(file_path):
|
4 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
5 |
+
content = file.read()
|
6 |
+
# 替换链接
|
7 |
+
content = content.replace('https://github.com/', 'https://ghp.ci/https://github.com/')
|
8 |
+
content = content.replace('https://raw.githubusercontent.com/', 'https://ghp.ci/https://raw.githubusercontent.com/')
|
9 |
+
content = content.replace('https://gist.github.com/', 'https://ghp.ci/https://gist.github.com/')
|
10 |
+
content = content.replace('https://gist.githubusercontent.com/', 'https://ghp.ci/https://gist.githubusercontent.com/')
|
11 |
+
# 写回文件
|
12 |
+
with open(file_path, 'w', encoding='utf-8') as file:
|
13 |
+
file.write(content)
|
14 |
+
|
15 |
+
def find_and_replace_links(directory):
|
16 |
+
for root, _, files in os.walk(directory):
|
17 |
+
for file in files:
|
18 |
+
if file.endswith('.py'):
|
19 |
+
file_path = os.path.join(root, file)
|
20 |
+
replace_links_in_file(file_path)
|
21 |
+
print(f"Processed file: {file_path}")
|
22 |
+
|
23 |
+
# 指定要查找的目录路径
|
24 |
+
directory_path = './'
|
25 |
+
find_and_replace_links(directory_path)
|