From 2da96dbe5a8eb77458a7952851eb9f14cc87b46b Mon Sep 17 00:00:00 2001 From: "Jeremy R. Manning" Date: Fri, 5 Jul 2024 16:02:44 -0400 Subject: [PATCH 1/5] add python function for creating a new problem note --- create_note.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 create_note.py 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("", problem_details['questionId']) +note_content = note_content.replace("", 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) From 77164b43895ab45428f161a93703fb48e3bd6b14 Mon Sep 17 00:00:00 2001 From: "Jeremy R. Manning" <jeremymanning@users.noreply.github.com> Date: Fri, 5 Jul 2024 16:09:59 -0400 Subject: [PATCH 2/5] new action for creating a new note for the daily problem --- .github/workflows/create_new_note.yml | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/create_new_note.yml diff --git a/.github/workflows/create_new_note.yml b/.github/workflows/create_new_note.yml new file mode 100644 index 0000000..4a96296 --- /dev/null +++ b/.github/workflows/create_new_note.yml @@ -0,0 +1,42 @@ +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 and create note + env: + GITHUB_USERNAME: ${{ github.actor }} + 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 + PROBLEM_ID=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.questionId' response.json) + 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}" + + # 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|<NUMBER>|${PROBLEM_ID}|g; s|<TITLE>|${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 ${PROBLEM_ID}" + branch: main + file_pattern: problems/*/*.md From 7912f1153d2b3fa27eb845ad3ee1926c0e02478e Mon Sep 17 00:00:00 2001 From: jeremymanning <jeremymanning@users.noreply.github.com> Date: Fri, 5 Jul 2024 20:10:52 +0000 Subject: [PATCH 3/5] Creating a template for jeremymanning's solution to problem ${PROBLEM_ID} --- problems/2182/jeremymanning.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 problems/2182/jeremymanning.md diff --git a/problems/2182/jeremymanning.md b/problems/2182/jeremymanning.md new file mode 100644 index 0000000..1d170ed --- /dev/null +++ b/problems/2182/jeremymanning.md @@ -0,0 +1,7 @@ +# [Problem 2182: Find the Minimum and Maximum Number of Nodes Between Critical Points](https://leetcode.com/problems/find-the-minimum-and-maximum-number-of-nodes-between-critical-points) + +## Initial thoughts (stream-of-consciousness) + +## Refining the problem + +## Attempted solution(s) From f14406cc759a6ff1ee2330bbbdea53b67dea1cc4 Mon Sep 17 00:00:00 2001 From: jeremymanning <jeremy.r.manning@dartmouth.edu> Date: Fri, 5 Jul 2024 16:13:37 -0400 Subject: [PATCH 4/5] removed wrong template --- .gitignore | 3 +++ problems/2182/jeremymanning.md | 7 ------- 2 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 problems/2182/jeremymanning.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/problems/2182/jeremymanning.md b/problems/2182/jeremymanning.md deleted file mode 100644 index 1d170ed..0000000 --- a/problems/2182/jeremymanning.md +++ /dev/null @@ -1,7 +0,0 @@ -# [Problem 2182: Find the Minimum and Maximum Number of Nodes Between Critical Points](https://leetcode.com/problems/find-the-minimum-and-maximum-number-of-nodes-between-critical-points) - -## Initial thoughts (stream-of-consciousness) - -## Refining the problem - -## Attempted solution(s) From 9aef23edbacb4debb8b937eb1e9883ca0b357279 Mon Sep 17 00:00:00 2001 From: "Jeremy R. Manning" <jeremymanning@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:07:22 -0400 Subject: [PATCH 5/5] Update "create new note" script --- .github/workflows/create_new_note.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/create_new_note.yml b/.github/workflows/create_new_note.yml index 4a96296..48d30d3 100644 --- a/.github/workflows/create_new_note.yml +++ b/.github/workflows/create_new_note.yml @@ -11,20 +11,22 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Fetch daily LeetCode problem details and create note - env: - GITHUB_USERNAME: ${{ github.actor }} + - 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 + # 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}" @@ -37,6 +39,6 @@ jobs: - 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 ${PROBLEM_ID}" + commit_message: "Creating a template for ${{ github.actor }}'s solution to problem ${{ steps.fetch_problem.outputs.problem_id }}" branch: main file_pattern: problems/*/*.md