Skip to content

Commit

Permalink
add leetcode.com support
Browse files Browse the repository at this point in the history
Signed-off-by: 胡金栋 <[email protected]>
  • Loading branch information
JamesHopbourn committed Mar 26, 2024
1 parent 083e24a commit 7a5f735
Show file tree
Hide file tree
Showing 4 changed files with 12,080 additions and 6,066 deletions.
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ Leetcode 题目搜素 Alfred Workflow

### 使用方法
#### lc 题目信息
搜索题目,并在 Leetcode 打开
搜索题目,并在 Leetcode 中国站打开
![](image/bilibili.png)

#### lcm 题目信息
搜索题目,并在 Leetcode 美国站打开
![](image/bilibili.png)

#### sxl 题目信息
搜素题目,在代码随想录中打开题解文章
![](image/programmercarl.png)

### 思路
1. 爬虫抓取所有题目
```shell
python leetcodeSpider.py > leetcode.json
```
2. 清洗数据
```shell
python processJSON.py > result.json
```
![](image/programmercarl.png)
14 changes: 11 additions & 3 deletions leetcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,27 @@ def camel_to_snake(camel_case_string):
data = json.loads(data)
result = []
for item in data:
item["icon"] = {}
item["icon"]["path"] = "icon.png"
if sys.argv[1].isalpha() and camel_to_snake(sys.argv[1]) in item["arg"]:
pass
elif sys.argv[1].lower() not in item["title"].lower():
continue
if os.environ['alfred_workflow_keyword'].lower() == "lc":
item["arg"] = f"https://leetcode.cn/problems/{item['arg']}/description/"
item['title'] = item['titleCN']
item['subtitle'] = item['subtitleCN']
result.append(item)
elif os.environ['alfred_workflow_keyword'].lower() == "lcm":
item["arg"] = f"https://leetcode.com/problems/{item['arg']}/description/"
item['title'] = item['titleUS']
item['subtitle'] = item['subtitleUS']
result.append(item)
else:
parts = item['title'].split(' ')
text = ''.join(parts[1:]).replace(' ', '')
formatted_title = '{:0>4}.{}.html'.format(parts[0], text)
item["arg"] = f"https://programmercarl.com/{formatted_title}"
item["icon"] = {}
item["icon"]["path"] = "icon.png"
result.append(item)
result.append(item)
alfredJSON = json.dumps({"items": result}, indent=2, ensure_ascii=False)
sys.stdout.write(alfredJSON)
Loading

0 comments on commit 7a5f735

Please sign in to comment.