diff --git a/.github/workflows/create_new_note.yml b/.github/workflows/create_new_note.yml new file mode 100644 index 0000000..48d30d3 --- /dev/null +++ b/.github/workflows/create_new_note.yml @@ -0,0 +1,44 @@ +name: Create New Note for Daily LeetCode Problem + +on: + workflow_dispatch: # Allows for manual triggering + +jobs: + create-note: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Fetch daily LeetCode problem details + id: fetch_problem + run: | + # Fetch problem details + curl -X POST -H 'Content-Type: application/json' \ + -d '{"query":"query questionOfToday { activeDailyCodingChallengeQuestion { date link question { questionId title titleSlug difficulty } } }","operationName":"questionOfToday"}' \ + https://leetcode.com/graphql -o response.json + + # Parse problem details and set outputs + PROBLEM_ID=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.questionId' response.json) + echo "::set-output name=problem_id::${PROBLEM_ID}" + + TITLE=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.title' response.json) + TITLE_SLUG=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.titleSlug' response.json) + LINK="https://leetcode.com/problems/${TITLE_SLUG}" + GITHUB_USERNAME="${{ github.actor }}" + + # Create problem directory and note + PROBLEM_DIR="problems/${PROBLEM_ID}" + NOTE_FILE="${PROBLEM_DIR}/${GITHUB_USERNAME}.md" + mkdir -p "${PROBLEM_DIR}" + + # Customize template and write to new file + sed "s||${PROBLEM_ID}|g; s||${TITLE}|g; s|<LINK TO DESCRIPTION>|${LINK}|g" problems/template.md > "${NOTE_FILE}" + + - name: Commit and push changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Creating a template for ${{ github.actor }}'s solution to problem ${{ steps.fetch_problem.outputs.problem_id }}" + branch: main + file_pattern: problems/*/*.md diff --git a/.gitignore b/.gitignore index 82f9275..e41de5d 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + + +.DS_Store \ No newline at end of file diff --git a/create_note.py b/create_note.py new file mode 100644 index 0000000..9045c32 --- /dev/null +++ b/create_note.py @@ -0,0 +1,28 @@ +import json +import os + +# Load problem details +with open("problem_details.json", "r") as f: + problem_details = json.load(f) + +# Define paths +template_path = "problems/template.md" +problem_dir = f"problems/{problem_details['questionId']}" +github_username = os.getenv('GITHUB_USERNAME') +problem_file = f"{problem_dir}/{github_username}.md" # Replace with actual username + +# Create problem directory if it doesn't exist +os.makedirs(problem_dir, exist_ok=True) + +# Read template content +with open(template_path, "r") as f: + template_content = f.read() + +# Customize template with problem details +note_content = template_content.replace("<NUMBER>", problem_details['questionId']) +note_content = note_content.replace("<TITLE>", problem_details['title']) +note_content = note_content.replace("<LINK TO DESCRIPTION>", problem_details['link']) + +# Write customized note to new file +with open(problem_file, "w") as f: + f.write(note_content)