Skip to content

Commit b8d4c46

Browse files
authored
feat: support leetcode.com (#75)
* feat: add us api * fix lint * cleanup * Add debugging * Implement us api * fix GetQuestionByFilter * fix contest question parse
1 parent e6f2a02 commit b8d4c46

File tree

12 files changed

+22627
-103
lines changed

12 files changed

+22627
-103
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- 通过模板引擎自定义配置生成的代码文件,支持对代码做预处理
2525
- 支持本地测试,可以使用 Debugger 调试代码
2626
- 自动等待并及时生成竞赛题目,一键提交所有题目
27-
- (即将) 同时支持 leetcode.com (美国站) 和 leetcode.cn (中国站)
27+
- 同时支持 leetcode.com (美国站) 和 leetcode.cn (中国站)
2828
- 自动从浏览器中读取 LeetCode 的 Cookie,无需手动提供
2929
- 自动在你喜欢的编辑器中打开生成的代码文件
3030

@@ -228,8 +228,6 @@ editor:
228228
229229
## LeetCode 支持情况
230230
231-
现阶段 `leetgo` 仅支持 `leetcode.cn` (中国站),`leetcode.com` (美国站) 的支持仍在开发中.
232-
233231
`leetgo` 使用 LeetCode 的 GraphQL API 来获取题目和提交代码,`leetgo` 需要 LeetCode 的 Cookie 来代替你做这些事情。
234232

235233
有三种方式为 `leetgo` 提供认证:

README_en.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ And `leetgo` also supports real-time generation of **contest questions**, so you
2525
- Customize the code template for generated code, use modifiers to preprocess code
2626
- Run test cases on your local machine
2727
- Wait and generate contest questions just in time, test and submit all at once
28-
- (Will) Support both leetcode.com and leetcode.cn
28+
- Support both leetcode.com and leetcode.cn
2929
- Read cookies from browser automatically, no need to provide password
3030
- Auto open question files in your favorite editor
3131

@@ -230,15 +230,13 @@ editor:
230230
231231
## LeetCode Support
232232
233-
Currently only `leetcode.cn` is supported. Support for `leetcode.com` is under development.
234-
235233
`leetgo` uses LeetCode's GraphQL API to get questions and submit solutions. `leetgo` needs your LeetCode cookies to access authenticated API.
236234

237235
There are three ways to provide cookies to `leetgo`:
238236

239237
- Read cookies from browser automatically.
240238

241-
Currently Chrome and FireFox are supported, if you want to support other browsers, please let us know!
239+
Currently, Chrome and FireFox are supported, if you want to support other browsers, please let us know!
242240

243241
```yaml
244242
leetcode:

cmd/info.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var infoCmd = &cobra.Command{
4848
},
4949
)
5050
for _, q := range questions {
51+
_ = q.Fulfill()
5152
w.AppendRow(
5253
table.Row{fmt.Sprintf("%s. %s", q.QuestionFrontendId, q.GetTitle())},
5354
table.RowConfig{AutoMerge: true, AutoMergeAlign: text.AlignLeft},

cmd/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ func UsageString() string {
7575
}
7676

7777
func initWorkDir() error {
78-
if os.Getenv("LEETGO_WORKDIR") != "" {
79-
return os.Chdir(os.Getenv("LEETGO_WORKDIR"))
78+
if dir := os.Getenv("LEETGO_WORKDIR"); dir != "" {
79+
hclog.L().Info("change workdir to LEETGO_WORKDIR", "dir", dir)
80+
return os.Chdir(dir)
8081
}
8182
return nil
8283
}

config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ func Load(init bool) error {
300300
if globalCfg != nil {
301301
return nil
302302
}
303+
// Convenient way to switch site during development
304+
if err := viper.BindEnv("leetcode.site", "LEETGO_SITE"); err != nil {
305+
return err
306+
}
303307

304308
// load global configuration
305309
cfg := Get()

0 commit comments

Comments
 (0)