Skip to content

Commit

Permalink
update leetcode.py code
Browse files Browse the repository at this point in the history
Signed-off-by: 胡金栋 <jameshopbourn@gmail.com>
  • Loading branch information
JamesHopbourn committed Mar 26, 2024
1 parent 7a5f735 commit 92678f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
4 changes: 1 addition & 3 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<dict>
<key>bundleid</key>
<string>com.hopbourn.leetcode-search</string>
<key>category</key>
<string>Productivity</string>
<key>connections</key>
<dict>
<key>3B4CA1A5-E71B-4073-9282-BFA5E25D49D6</key>
Expand Down Expand Up @@ -48,7 +46,7 @@
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>lc||sxl</string>
<string>lc||lcm||sxl</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
Expand Down
14 changes: 4 additions & 10 deletions leetcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@
import sys
import json

def camel_to_snake(camel_case_string):
snake_case_string = re.sub(r'([A-Z])', r'-\1', camel_case_string)
return snake_case_string.lstrip('-').lower()

data = open('result.json').read()
data = json.loads(data)
result = []
for item in data:
if sys.argv[1] not in item["titleCN"] and sys.argv[1].lower() not in item["titleUS"].lower():
continue
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']
Expand All @@ -27,8 +21,8 @@ def camel_to_snake(camel_case_string):
item['title'] = item['titleUS']
item['subtitle'] = item['subtitleUS']
result.append(item)
else:
parts = item['title'].split(' ')
elif os.environ['alfred_workflow_keyword'].lower() == "sxl":
parts = item['titleCN'].split(' ')
text = ''.join(parts[1:]).replace(' ', '')
formatted_title = '{:0>4}.{}.html'.format(parts[0], text)
item["arg"] = f"https://programmercarl.com/{formatted_title}"
Expand Down

0 comments on commit 92678f5

Please sign in to comment.