Skip to content

Commit d7f3225

Browse files
Merge pull request #13 from ContextLab/main
merging updates from main
2 parents 7203d8e + 9aef23e commit d7f3225

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

.github/workflows/create_new_note.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Create New Note for Daily LeetCode Problem
2+
3+
on:
4+
workflow_dispatch: # Allows for manual triggering
5+
6+
jobs:
7+
create-note:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v2
13+
14+
- name: Fetch daily LeetCode problem details
15+
id: fetch_problem
16+
run: |
17+
# Fetch problem details
18+
curl -X POST -H 'Content-Type: application/json' \
19+
-d '{"query":"query questionOfToday { activeDailyCodingChallengeQuestion { date link question { questionId title titleSlug difficulty } } }","operationName":"questionOfToday"}' \
20+
https://leetcode.com/graphql -o response.json
21+
22+
# Parse problem details and set outputs
23+
PROBLEM_ID=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.questionId' response.json)
24+
echo "::set-output name=problem_id::${PROBLEM_ID}"
25+
26+
TITLE=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.title' response.json)
27+
TITLE_SLUG=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.titleSlug' response.json)
28+
LINK="https://leetcode.com/problems/${TITLE_SLUG}"
29+
GITHUB_USERNAME="${{ github.actor }}"
30+
31+
# Create problem directory and note
32+
PROBLEM_DIR="problems/${PROBLEM_ID}"
33+
NOTE_FILE="${PROBLEM_DIR}/${GITHUB_USERNAME}.md"
34+
mkdir -p "${PROBLEM_DIR}"
35+
36+
# Customize template and write to new file
37+
sed "s|<NUMBER>|${PROBLEM_ID}|g; s|<TITLE>|${TITLE}|g; s|<LINK TO DESCRIPTION>|${LINK}|g" problems/template.md > "${NOTE_FILE}"
38+
39+
- name: Commit and push changes
40+
uses: stefanzweifel/git-auto-commit-action@v4
41+
with:
42+
commit_message: "Creating a template for ${{ github.actor }}'s solution to problem ${{ steps.fetch_problem.outputs.problem_id }}"
43+
branch: main
44+
file_pattern: problems/*/*.md

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,6 @@ cython_debug/
160160
# and can be added to the global gitignore or merged into this file. For a more nuclear
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162162
#.idea/
163+
164+
165+
.DS_Store

create_note.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import json
2+
import os
3+
4+
# Load problem details
5+
with open("problem_details.json", "r") as f:
6+
problem_details = json.load(f)
7+
8+
# Define paths
9+
template_path = "problems/template.md"
10+
problem_dir = f"problems/{problem_details['questionId']}"
11+
github_username = os.getenv('GITHUB_USERNAME')
12+
problem_file = f"{problem_dir}/{github_username}.md" # Replace with actual username
13+
14+
# Create problem directory if it doesn't exist
15+
os.makedirs(problem_dir, exist_ok=True)
16+
17+
# Read template content
18+
with open(template_path, "r") as f:
19+
template_content = f.read()
20+
21+
# Customize template with problem details
22+
note_content = template_content.replace("<NUMBER>", problem_details['questionId'])
23+
note_content = note_content.replace("<TITLE>", problem_details['title'])
24+
note_content = note_content.replace("<LINK TO DESCRIPTION>", problem_details['link'])
25+
26+
# Write customized note to new file
27+
with open(problem_file, "w") as f:
28+
f.write(note_content)

0 commit comments

Comments
 (0)