Skip to content

Commit

Permalink
Update README_automation.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Mo-Shakib authored Oct 31, 2024
1 parent 6d206f3 commit 9b57a48
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions README_automation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# GitHub README.md automation script by Mohammad Shakib
# This script can automatically update the readme file based on the files present in the repo.
# Last update: 29-11-2024
# Version - v3.5.0
# Version - v3.6.0

import os, time, markdown, re
from datetime import datetime
Expand All @@ -10,10 +10,10 @@
def get_date(epoch_time):
return datetime.fromtimestamp(epoch_time)

def create_problem_description_file(file_path, root_directory):
def create_problem_description_file(file_path, src_directory):
filename = os.path.basename(file_path)
description_filename = os.path.splitext(filename)[0] + ".md" # Save description as .md
description_path = os.path.join(root_directory, description_filename)
description_path = os.path.join(src_directory, description_filename)

with open(file_path, 'r') as file:
lines = file.readlines()
Expand Down Expand Up @@ -53,7 +53,7 @@ def create_problem_description_file(file_path, root_directory):

formatted_description_content = format_description(description_content)

# Save to the root directory as a .md file (overwrite if exists)
# Save to the /src directory as a .md file (overwrite if exists)
with open(description_path, 'w') as desc_file:
desc_file.write(formatted_description_content)
desc_file.write("**Solution Code**:\n")
Expand Down Expand Up @@ -106,6 +106,10 @@ def format_description(content):
def process_directory(root_directory):
subdirectories = ["easy", "medium", "hard"]

# Set the /src directory path
src_directory = os.path.join(root_directory, "src")
os.makedirs(src_directory, exist_ok=True)

# Custom header for the README.md file
readme_header = """# LeetCode Solutions
Expand All @@ -117,6 +121,7 @@ def process_directory(root_directory):
### Repository Structure
**The repository is organized into three main folders based on difficulty:**
```
LeetCode/
├── easy/
Expand All @@ -135,9 +140,9 @@ def process_directory(root_directory):
for filename in os.listdir(dir_path):
if filename.endswith(".py"):
file_path = os.path.join(dir_path, filename)
problem_id, title, url, description_filename = create_problem_description_file(file_path, root_directory)
# Add entry to the section's list format
readme_lines.append(f"- [{title}]({url}) - [Solution]({description_filename})")
problem_id, title, url, description_filename = create_problem_description_file(file_path, src_directory)
# Link updated to point to src directory
readme_lines.append(f"- [{title}]({url}) - [Solution](src/{description_filename})")


readme_path = os.path.join(root_directory, "README.md")
Expand All @@ -150,6 +155,9 @@ def process_directory(root_directory):
root_directory = os.path.dirname(__file__)
process_directory(root_directory)

print('[=] README.md updated.')
time.sleep(1)

# print('[=] Task Successfull')

# current_time = datetime.now(pytz.timezone('Asia/Dhaka'))
Expand Down

0 comments on commit 9b57a48

Please sign in to comment.