Skip to content

Commit 17a3779

Browse files
committed
title keyword search
Signed-off-by: 胡金栋 <[email protected]>
1 parent 35b7356 commit 17a3779

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Diff for: README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# leetcode-alfred-workflow
22
Leetcode Problem Search Alfred Workflow
33

4+
- [x] 题号搜素
5+
- [x] 题目搜素
6+
- [x] 关键词模糊搜索
7+
- [x] 中美国站点支持
8+
49
## 使用说明 | Usage
510
| 命令 command | 解释 explain | 例子 example |
611
| :---------: | ----------- | ------------ |
7-
| lc | 搜索题目,并在 LeetCode 中国站打开<br><br>Search for problems and open on LeetCode China site | ```lc 94```<br>```lc 二叉树```<br>```lc two sum``` |
8-
| lcm | 搜索题目,并在 LeetCode 美国站打开<br><br>Search for problems and open on LeetCode US site | ```lcm 94```<br>```lcm Tree```<br>```lcm two sum``` |
12+
| lc | 搜索题目,并在 LeetCode 中国站打开<br><br>Search for problems and open on LeetCode China site | ```lc 94```<br>```lc 二叉树```<br>```lc two sum```<br>```lc 树 遍历``` |
13+
| lcm | 搜索题目,并在 LeetCode 美国站打开<br><br>Search for problems and open on LeetCode US site | ```lcm 94```<br>```lcm tree```<br>```lcm two sum```<br>```lc tree order``` |
914
| sxl | 搜索题目,在 [programmercarl.com](https://programmercarl.com/) 中打开题解文章<br><br>Search for problems and open on [programmercarl.com](https://programmercarl.com/) | ```sxl 123```<br>```sxl 买卖股票```<br>```sxl two sum``` |

Diff for: leetcode.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55

66
data = open('result.json').read()
77
data = json.loads(data)
8+
9+
text = ' '.join(sys.argv[1:])
10+
text = '.*' + '.*'.join(text.split()) + '.*'
11+
812
result = []
913
for item in data:
10-
if sys.argv[1] not in item['titleCN'] and sys.argv[1].lower() not in item['titleUS'].lower():
14+
# 匹配中文或者英文标题
15+
if not re.search(text.lower(), item['titleCN'] + item['titleUS'].lower()):
1116
continue
1217
# lc 和 sxl 公共字段提取,遇到 lcm 关键词再覆盖
1318
item['icon'] = {'path': 'icon.png'}
1419
item['title'], item['subtitle'] = item['titleCN'], item['subtitleCN']
20+
# lc 和 sxl 公共字段提取,遇到 lcm 关键词再覆盖
21+
item['icon'] = {'path': 'icon.png'}
22+
item['title'], item['subtitle'] = item['titleCN'], item['subtitleCN']
1523
keyword = os.environ['alfred_workflow_keyword'].lower()
1624
if keyword == 'lc':
1725
item['arg'] = f"https://leetcode.cn/problems/{item['arg']}/description/"

0 commit comments

Comments
 (0)