-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrep_github.py
More file actions
27 lines (24 loc) · 1.25 KB
/
rep_github.py
File metadata and controls
27 lines (24 loc) · 1.25 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
import os
def replace_links_in_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# 替换链接
content = content.replace('https://gh-proxy.com/', '')
content = content.replace('https://github.com/', 'https://gh-proxy.com/https://github.com/')
content = content.replace('https://raw.githubusercontent.com/', 'https://gh-proxy.com/https://raw.githubusercontent.com/')
content = content.replace('https://gist.github.com/', 'https://gh-proxy.com/https://gist.github.com/')
content = content.replace('https://gist.githubusercontent.com/', 'https://gh-proxy.com/https://gist.githubusercontent.com/')
content = content.replace('https://huggingface.co', 'https://hf-mirror.com')
# 写回文件
with open(file_path, 'w', encoding='utf-8') as file:
file.write(content)
def find_and_replace_links(directory):
for root, _, files in os.walk(directory):
for file in files:
if file.endswith('.py'):
file_path = os.path.join(root, file)
replace_links_in_file(file_path)
print(f"Processed file: {file_path}")
# 指定要查找的目录路径
directory_path = './stable-diffusion-webui'
find_and_replace_links(directory_path)