Last active
April 25, 2024 07:24
-
-
Save szy0syz/5b67d71b7a91df9a09a5c12d7d81c70b to your computer and use it in GitHub Desktop.
merge code to md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
def find_files(root_dir, extensions): | |
js_ts_md_files = [] | |
for root, dirs, files in os.walk(root_dir): | |
for file in files: | |
for ext in extensions: | |
if file.endswith(ext): | |
file_path = os.path.join(root, file) | |
js_ts_md_files.append(file_path) | |
break | |
return js_ts_md_files | |
def get_relative_path(file_path, root_dir): | |
return os.path.relpath(file_path, root_dir) | |
def read_and_write_files(files, output_file, root_dir): | |
with open(output_file, 'w') as output: | |
for file_path in files: | |
with open(file_path, 'r') as file: | |
content = file.read() | |
content = content.replace('com.com', 'abc.org') | |
file_name = os.path.basename(file_path) | |
output.write(f"## {file_name}\n\n```\n{content}\n```\n\n") | |
def main(): | |
if len(sys.argv) < 4: | |
print("Usage: python script.py /path/to/your/github/repo output.md .js .ts") | |
sys.exit(1) | |
root_dir = sys.argv[1] | |
output_file = sys.argv[2] | |
extensions = sys.argv[3:] | |
files = find_files(root_dir, extensions) | |
read_and_write_files(files, output_file, root_dir) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment