8000 Merge pull request #2 from noworneverev/refactor/repo-structure · noworneverev/leetcode-api@ba75309 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba75309

Browse files
authored
Merge pull request #2 from noworneverev/refactor/repo-structure
Refactor repo structure
2 parents fe89922 + 08906b1 commit ba75309

File tree

8 files changed

+32
-9
lines changed

8 files changed

+32
-9
lines changed

.github/workflows/daily_download.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Run download.py
2424
env:
2525
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
26-
run: python download.py
26+
run: python src/utils/download.py
2727

2828
- name: Commit and Push changes
2929
run: |

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,32 @@ curl https://leetcode-api-pied.vercel.app/user/lee215
4949
cd leetcode-api
5050
```
5151

52-
2. Install dependencies
52+
2. Set up virtual environment (recommended)
53+
```bash
54+
python -m venv venv
55+
source venv/bin/activate # Linux/MacOS
56+
venv\Scripts\activate # Windows
57+
```
58+
59+
4. Install dependencies
5360
```bash
5461
pip install -r requirements.txt
5562
```
5663

57-
3. Run the server
64+
5. Run the server
5865
```bash
59-
python api.py
66+
python run.py
6067
```
68+
Visit http://localhost:8000/docs for local Swagger docs!
69+
6170

62-
Visit http://localhost:8000/docs for local Swagger docs!
71+
## 🔄 Daily Updated Full Problems JSON
72+
73+
Get the latest LeetCode problems. Either run:
74+
```bash
75+
python -m src.utils.download
76+
```
77+
or download `leetcode_questions.json`(updated daily) directly from the `data` folder.
6378

6479
## 🤔 Why This API?
6580
- Always Fresh Data 🥬

run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import runpy
2+
3+
if __name__ == '__main__':
4+
runpy.run_module('src.api.api', run_name='__main__')

src/__init__.py

Whitespace-only changes.

api.py renamed to src/api/api.py

File renamed without changes.

download.py renamed to src/utils/download.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import time
33
import random
44
import json
5-
from utils import get_google_sheets_service, prepare_sheet_data, update_google_sheet
5+
import os
6+
from src.utils.google_sheets import get_google_sheets_service, prepare_sheet_data, update_google_sheet
67

78
url = "https://leetcode.com/graphql"
89

@@ -110,7 +111,10 @@
110111
if retries == max_retries:
111112
print(f"Max retries reached for: (ID: {question_id}) {question['title']}. Skipping...")
112113

113-
with open("./data/leetcode_questions.json", "w") as f:
114+
data_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "data", "leetcode_questions.json"))
115+
os.makedirs(os.path.dirname(data_file_path), exist_ok=True)
116+
117+
with open(data_file_path, "w") as f:
114118
json.dump(all_questions_data, f, indent=2)
115119

116120
print("All questions' data saved to leetcode_questions.json")
File renamed without changes.

vercel.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"version": 2,
33
"builds": [
44
{
5-
"src": "api.py",
5+
"src": "run.py",
66
"use": "@vercel/python"
77
}
88
],
99
"routes": [
1010
{
1111
"src": "/(.*)",
12-
"dest": "api.py"
12+
"dest": "run.py"
1313
}
1414
]
1515
}

0 commit comments

Comments
 (0)
0