Skip to content

Commit eaa963d

Browse files
committed
workbook 자동화
1 parent 9a4ecbf commit eaa963d

File tree

10 files changed

+50
-20
lines changed

10 files changed

+50
-20
lines changed

.github/workflows/update.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Python application
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write # ✅ Push 권한을 위해 필요
13+
14+
steps:
15+
- name: Checkout the repository
16+
uses: actions/checkout@v2
17+
with:
18+
token: ${{ secrets.GITHUB_TOKEN }} # ✅ 자동 제공 토큰 사용
19+
20+
- name: Set up Python 3.9
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: 3.9
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install requests
29+
- name: Run code
30+
run: |
31+
cd workbook
32+
python actions.py
33+
- name: Commit and Push Changes
34+
run: |
35+
git config user.name github-actions
36+
git config user.email [email protected]
37+
git add workbook/
38+
git commit -m "Auto-generate workbook for branch ${{ github.ref_name }}" || echo "No changes to commit"
39+
git push origin HEAD
File renamed without changes.
File renamed without changes.

Array/11328-Strfry.java renamed to 0x03/solutions/11328-Strfry.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import java.io.*;
2-
import java.util.*;
32

43
public class Main {
54

File renamed without changes.
File renamed without changes.

Array/1919-에너그램만들기.java renamed to 0x03/solutions/1919-에너그램만들기.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import java.io.*;
2-
import java.util.*;
32

43
public class Main {
54

Array/2577-숫자의개수.java renamed to 0x03/solutions/2577-숫자의개수.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import java.io.*;
2-
import java.util.*;
32

43
public class Main {
54

File renamed without changes.

workbook/actions.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def get_problem_info(workbook_url):
2525
ret = []
2626
while True:
2727
x = txt.find(pattern)
28+
print(x)
2829
if x == -1: break
2930
txt = txt[x+9:]
3031
prob_id, prob_name = '', ''
@@ -42,19 +43,12 @@ def get_problem_info(workbook_url):
4243

4344
CATEGORY = ["연습 문제", "기본 문제✔", "기본 문제", "응용 문제✔", "응용 문제"]
4445

45-
# gen 0x00.md to 0x??.md, proper prob_id.cpp for each solution directory
46+
# gen 0x00.md to 0x??.md, proper prob_id.java for each solution directory
4647
def gen_ind_workbook(attrs, category):
4748
txt = '''// Authored by : BaaaaaaaaaaarkingDog
4849
// Co-authored by : -
4950
// http://boj.kr/****************
50-
#include <bits/stdc++.h>
51-
using namespace std;
52-
53-
int main(void){
54-
ios::sync_with_stdio(0);
55-
cin.tie(0);
56-
57-
}'''
51+
'''
5852
chapter_idx = 0
5953
for attr in attrs:
6054
if len(attr) < 3: # No workbook
@@ -69,24 +63,24 @@ def gen_ind_workbook(attrs, category):
6963
if prob_id in category[chapter_idx]:
7064
category_idx = category[chapter_idx].index(prob_id)
7165
file_path = solution_path + prob_id
72-
if not os.path.exists(file_path + '.cpp'):
73-
with open(file_path + '.cpp', 'w', encoding="UTF-8") as f:
66+
if not os.path.exists(file_path + '.java'):
67+
with open(file_path + '.java', 'w', encoding="UTF-8") as f:
7468
f.write(txt)
7569
try:
76-
codes = open(file_path + '.cpp', 'r', encoding="UTF-8").read()
70+
codes = open(file_path + '.java', 'r', encoding="UTF-8").read()
7771
except: # EUC-KR -> UTF-8
78-
codes = open(file_path + '.cpp', 'r', encoding="EUC-KR").read()
79-
with open(file_path + '.cpp', 'w', encoding="UTF-8") as fw:
72+
codes = open(file_path + '.java', 'r', encoding="EUC-KR").read()
73+
with open(file_path + '.java', 'w', encoding="UTF-8") as fw:
8074
fw.write(codes)
8175
if codes[:100] == txt[:100]:
8276
prob_table += f'| {CATEGORY[category_idx]} | {prob_id} | [{prob_name}](https://www.acmicpc.net/problem/{prob_id}) | - |\n'
8377
else:
8478
solution_num += 1
85-
code_attr = f'[정답 코드]({file_path.replace(" ", "%20")}.cpp)'
79+
code_attr = f'[정답 코드]({file_path.replace(" ", "%20")}.java)'
8680
MAX_DIFFERENT_SOLUTION = 9
8781
for i in range(1, MAX_DIFFERENT_SOLUTION+1):
88-
if os.path.exists(file_path+'_'+str(i)+'.cpp'):
89-
code_attr += f", [별해 {i}]({file_path+'_'+str(i)+'.cpp'})"
82+
if os.path.exists(file_path+'_'+str(i)+'.java'):
83+
code_attr += f", [별해 {i}]({file_path+'_'+str(i)+'.java'})"
9084
prob_table += f'| {CATEGORY[category_idx]} | {prob_id} | [{prob_name}](https://www.acmicpc.net/problem/{prob_id}) | {code_attr} |\n'
9185
with open(attr[0]+'.md', 'w', encoding="UTF-8") as f:
9286
# progress bar

0 commit comments

Comments
 (0)