Skip to content

Commit

Permalink
title keyword search
Browse files Browse the repository at this point in the history
Signed-off-by: 胡金栋 <jameshopbourn@gmail.com>
  • Loading branch information
JamesHopbourn committed Mar 29, 2024
1 parent 35b7356 commit 17a3779
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# leetcode-alfred-workflow
Leetcode Problem Search Alfred Workflow

- [x] 题号搜素
- [x] 题目搜素
- [x] 关键词模糊搜索
- [x] 中美国站点支持

## 使用说明 | Usage
| 命令 command | 解释 explain | 例子 example |
| :---------: | ----------- | ------------ |
| lc | 搜索题目,并在 LeetCode 中国站打开<br><br>Search for problems and open on LeetCode China site | ```lc 94```<br>```lc 二叉树```<br>```lc two sum``` |
| lcm | 搜索题目,并在 LeetCode 美国站打开<br><br>Search for problems and open on LeetCode US site | ```lcm 94```<br>```lcm Tree```<br>```lcm two sum``` |
| lc | 搜索题目,并在 LeetCode 中国站打开<br><br>Search for problems and open on LeetCode China site | ```lc 94```<br>```lc 二叉树```<br>```lc two sum```<br>```lc 树 遍历``` |
| 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``` |
| 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``` |
10 changes: 9 additions & 1 deletion leetcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@

data = open('result.json').read()
data = json.loads(data)

text = ' '.join(sys.argv[1:])
text = '.*' + '.*'.join(text.split()) + '.*'

result = []
for item in data:
if sys.argv[1] not in item['titleCN'] and sys.argv[1].lower() not in item['titleUS'].lower():
# 匹配中文或者英文标题
if not re.search(text.lower(), item['titleCN'] + item['titleUS'].lower()):
continue
# lc 和 sxl 公共字段提取,遇到 lcm 关键词再覆盖
item['icon'] = {'path': 'icon.png'}
item['title'], item['subtitle'] = item['titleCN'], item['subtitleCN']
# lc 和 sxl 公共字段提取,遇到 lcm 关键词再覆盖
item['icon'] = {'path': 'icon.png'}
item['title'], item['subtitle'] = item['titleCN'], item['subtitleCN']
keyword = os.environ['alfred_workflow_keyword'].lower()
if keyword == 'lc':
item['arg'] = f"https://leetcode.cn/problems/{item['arg']}/description/"
Expand Down

0 comments on commit 17a3779

Please sign in to comment.