Last active
August 26, 2024 15:58
-
-
Save s-smits/a86788810f2e7e9217b29993c1812972 to your computer and use it in GitHub Desktop.
combine.py
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 glob | |
import time | |
# Define the paths to the backend and frontend folders | |
backend_path = '/Users/air/Repositories/.../backend' | |
frontend_path = '/Users/air/Repositories/.../frontend' | |
while True: | |
# Create a list to hold the paths of all .py files for backend, excluding venv_document_analysis_3.10/ | |
backend_file_paths = glob.glob(os.path.join(backend_path, '**/*.py'), recursive=True) | |
backend_file_paths = [path for path in backend_file_paths if 'venv_document_analysis_3.10' not in path] | |
# Create a list to hold the paths of all .ts, .js, .html, and .css files for frontend, excluding node_modules | |
frontend_file_paths = glob.glob(os.path.join(frontend_path, '**/*.tsx'), recursive=True) + \ | |
glob.glob(os.path.join(frontend_path, '**/*.ts'), recursive=True) + \ | |
glob.glob(os.path.join(frontend_path, '**/*.js'), recursive=True) + \ | |
glob.glob(os.path.join(frontend_path, '**/*.html'), recursive=True) + \ | |
glob.glob(os.path.join(frontend_path, '**/*.css'), recursive=True) | |
frontend_file_paths = [path for path in frontend_file_paths if 'node_modules' not in path and 'build' not in path] | |
print("backend_file_paths", backend_file_paths) | |
print("frontend_file_paths", frontend_file_paths) | |
# Open the frontend.txt file in write mode for frontend | |
with open('frontend.txt', 'w', encoding='utf-8') as outfile: | |
# Iterate over the list of frontend file paths | |
for file_path in frontend_file_paths: | |
# Write the file name as a header | |
outfile.write(f"\n\n# File: {os.path.relpath(file_path, frontend_path)}\n") | |
# Open each file in read mode with UTF-8 encoding | |
try: | |
with open(file_path, 'r', encoding='utf-8') as infile: | |
# Read the content of the file and write it to the frontend.txt file | |
outfile.write(infile.read()) | |
except UnicodeDecodeError: | |
print(f"Warning: Unable to read {file_path} with UTF-8 encoding. Skipping this file.") | |
print(f"Combined {len(frontend_file_paths)} frontend files from {frontend_path} into frontend.txt") | |
# Open the src.txt file in write mode for backend | |
with open('src.txt', 'w', encoding='utf-8') as outfile: | |
# Iterate over the list of backend file paths | |
for file_path in backend_file_paths: | |
# Write the file name as a header | |
outfile.write(f"\n\n# File: {os.path.relpath(file_path, backend_path)}\n") | |
# Open each file in read mode with UTF-8 encoding | |
try: | |
with open(file_path, 'r', encoding='utf-8') as infile: | |
# Read the content of the file and write it to the src.txt file | |
outfile.write(infile.read()) | |
except UnicodeDecodeError: | |
print(f"Warning: Unable to read {file_path} with UTF-8 encoding. Skipping this file.") | |
print(f"Combined {len(backend_file_paths)} Python files from {backend_path} into src.txt") | |
# Open the both.txt file in write mode to combine frontend and backend | |
with open('both.txt', 'w', encoding='utf-8') as outfile: | |
# First write frontend content | |
with open('frontend.txt', 'r', encoding='utf-8') as frontend_file: | |
outfile.write(frontend_file.read()) | |
# Then write backend content | |
with open('src.txt', 'r', encoding='utf-8') as backend_file: | |
outfile.write(backend_file.read()) | |
print("Combined frontend and backend files into both.txt") | |
# Wait for 5 seconds before the next execution | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment