diff --git a/README.md b/README.md index ae15124..f3acf5e 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,14 @@ # leetcode-alfred-workflow Leetcode Problem Search Alfred Workflow +- [x] 题号搜素 +- [x] 题目搜素 +- [x] 关键词模糊搜索 +- [x] 中美国站点支持 + ## 使用说明 | Usage | 命令 command | 解释 explain | 例子 example | | :---------: | ----------- | ------------ | -| lc | 搜索题目,并在 LeetCode 中国站打开

Search for problems and open on LeetCode China site | ```lc 94```
```lc 二叉树```
```lc two sum``` | -| lcm | 搜索题目,并在 LeetCode 美国站打开

Search for problems and open on LeetCode US site | ```lcm 94```
```lcm Tree```
```lcm two sum``` | +| lc | 搜索题目,并在 LeetCode 中国站打开

Search for problems and open on LeetCode China site | ```lc 94```
```lc 二叉树```
```lc two sum```
```lc 树 遍历``` | +| lcm | 搜索题目,并在 LeetCode 美国站打开

Search for problems and open on LeetCode US site | ```lcm 94```
```lcm tree```
```lcm two sum```
```lc tree order``` | | sxl | 搜索题目,在 [programmercarl.com](https://programmercarl.com/) 中打开题解文章

Search for problems and open on [programmercarl.com](https://programmercarl.com/) | ```sxl 123```
```sxl 买卖股票```
```sxl two sum``` | diff --git a/leetcode.py b/leetcode.py index b189591..cd4d1bc 100644 --- a/leetcode.py +++ b/leetcode.py @@ -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/"