-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to search by emoji instead
- Loading branch information
1 parent
36702a5
commit 236fe85
Showing
15 changed files
with
209 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ build/ | |
dist/ | ||
releases/ | ||
|
||
tmp.py | ||
|
||
.venv/ | ||
.idea/ | ||
.tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
alfred-pyflow==0.4.6 ; python_version >= "3.8" and python_version < "3.12" | ||
certifi==2023.11.17 ; python_version >= "3.8" and python_version < "3.12" | ||
charset-normalizer==3.3.2 ; python_version >= "3.8" and python_version < "3.12" | ||
emoji==2.10.1 ; python_version >= "3.8" and python_version < "3.12" | ||
fuzzywuzzy==0.18.0 ; python_version >= "3.8" and python_version < "3.12" | ||
idna==3.6 ; python_version >= "3.8" and python_version < "3.12" | ||
requests==2.31.0 ; python_version >= "3.8" and python_version < "3.12" | ||
urllib3==1.26.6 ; python_version >= "3.8" and python_version < "3.12" | ||
alfred-pyflow==0.4.7 ; python_version >= "3.8" and python_version < "4.0" | ||
certifi==2024.7.4 ; python_version >= "3.8" and python_version < "4.0" | ||
charset-normalizer==3.3.2 ; python_version >= "3.8" and python_version < "4.0" | ||
emoji==2.12.1 ; python_version >= "3.8" and python_version < "4.0" | ||
fuzzywuzzy==0.18.0 ; python_version >= "3.8" and python_version < "4.0" | ||
idna==3.8 ; python_version >= "3.8" and python_version < "4.0" | ||
requests==2.32.3 ; python_version >= "3.8" and python_version < "4.0" | ||
typing-extensions==4.12.2 ; python_version >= "3.8" and python_version < "4.0" | ||
urllib3==2.2.1 ; python_version >= "3.8" and python_version < "4.0" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,4 +97,4 @@ def build(): | |
yield alias, code | ||
|
||
|
||
emojis = list(build()) | ||
emojis = list(build()) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import sys | ||
|
||
from pyflow import Workflow | ||
|
||
import utils | ||
|
||
|
||
def main(workflow: Workflow): | ||
text = " ".join(workflow.args).lower() | ||
results = utils.search_by_emoji(text, limit=20) | ||
|
||
for ratio, (name, code) in results: | ||
workflow.new_item( | ||
title=f"{code} {name}", | ||
arg=name, | ||
copytext=name, | ||
valid=True, | ||
).set_icon_file( | ||
path=None, | ||
).set_cmd_mod( | ||
subtitle=f"Match: {ratio:.2f}", | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
wf = Workflow() | ||
wf.run(main) | ||
wf.send_feedback() | ||
sys.exit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import sys | ||
|
||
from pyflow import Workflow | ||
|
||
import utils | ||
|
||
|
||
def main(workflow: Workflow): | ||
text = " ".join(workflow.args).lower() | ||
results = utils.search_by_text(text, limit=20) | ||
|
||
for ratio, (name, code) in results: | ||
workflow.new_item( | ||
title=f"{code} {name}", | ||
arg=code, | ||
copytext=code, | ||
valid=True, | ||
).set_icon_file( | ||
path=None, | ||
).set_cmd_mod( | ||
subtitle=f"Match: {ratio:.2f}", | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
wf = Workflow() | ||
wf.run(main) | ||
wf.send_feedback() | ||
sys.exit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from difflib import SequenceMatcher | ||
from typing import Iterable, Tuple | ||
|
||
from emojis import emojis | ||
|
||
|
||
def match(s1, s2): | ||
ratio = SequenceMatcher(None, s1, s2).ratio() | ||
|
||
if s2 in s1: | ||
ratio *= 3 | ||
|
||
return 100 * ratio | ||
|
||
|
||
def search_by_text(text: str, limit: int = 10): | ||
return search(text, limit, index=0, min_ratio=1) | ||
|
||
|
||
def search_by_emoji(text: str, limit: int = 10): | ||
return search(text, limit, index=1, min_ratio=50.0) | ||
|
||
|
||
def search(text: str, limit: int = 10, index: int = 0, min_ratio: float = 0): | ||
result = sorted( | ||
filter( | ||
lambda item: item[0] >= min_ratio, | ||
map( | ||
lambda item: (match(item[index], text), item), | ||
emojis, | ||
), | ||
), | ||
key=lambda item: item[0], | ||
reverse=True, | ||
) | ||
|
||
return list(result)[:limit] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from pyflow.testing import WorklowTestCase | ||
|
||
from search_emoji import main | ||
|
||
|
||
class TestMain(WorklowTestCase): | ||
def test_run(self): | ||
workflow = self.workflow() | ||
feedback = self.run_workflow(workflow, main, "🇦🇷") | ||
|
||
found = "" | ||
|
||
for item in feedback["items"]: | ||
found += item["arg"] | ||
|
||
self.assertEqual(found, "argentina") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters