Skip to content

Commit

Permalink
Add a way to search by emoji instead
Browse files Browse the repository at this point in the history
  • Loading branch information
fedecalendino committed Aug 25, 2024
1 parent 36702a5 commit 236fe85
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ build/
dist/
releases/

tmp.py

.venv/
.idea/
.tmp/
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@

#### Usage:

![usage vars](screenshots/usage.png)
![usage example](screenshots/usage.png)

![search by text example](screenshots/search by text.png)

![search by emoji example](screenshots/search by emoji.png)

89 changes: 79 additions & 10 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
<string>Productivity</string>
<key>connections</key>
<dict>
<key>8B087B9B-EF04-49BF-B7DF-710AE605EFC7</key>
<array>
<dict>
<key>destinationuid</key>
<string>1F6B084F-ECB0-4573-B67E-E110AEB00649</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>98FFB671-15EA-49E0-AA9B-77570204157B</key>
<array>
<dict>
Expand All @@ -32,6 +45,55 @@
<string>Emoji Mate</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>0</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>{var:keyword}</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<false/>
<key>queuedelaymode</key>
<integer>1</integer>
<key>queuemode</key>
<integer>2</integer>
<key>runningsubtext</key>
<string>Searching...</string>
<key>script</key>
<string>/usr/bin/python3 ./dist/search_text.py $@</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>For example: mate</string>
<key>title</key>
<string>Search by text</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>98FFB671-15EA-49E0-AA9B-77570204157B</string>
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -63,11 +125,11 @@
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>1</integer>
<integer>0</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>{var:keyword}</string>
<string>{var:keyword}?</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
Expand All @@ -77,26 +139,26 @@
<key>queuemode</key>
<integer>2</integer>
<key>runningsubtext</key>
<string>Searching for emojis...</string>
<string>Searching...</string>
<key>script</key>
<string>/usr/bin/python3 ./dist/main.py $@</string>
<string>/usr/bin/python3 ./dist/search_emoji.py $@</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>For example: mate</string>
<string>For example: 🧉</string>
<key>title</key>
<string>Input text to search emojis</string>
<string>Search by emoji</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<false/>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>98FFB671-15EA-49E0-AA9B-77570204157B</string>
<string>8B087B9B-EF04-49BF-B7DF-710AE605EFC7</string>
<key>version</key>
<integer>3</integer>
</dict>
Expand All @@ -110,7 +172,14 @@
<key>xpos</key>
<real>280</real>
<key>ypos</key>
<real>15</real>
<real>75</real>
</dict>
<key>8B087B9B-EF04-49BF-B7DF-710AE605EFC7</key>
<dict>
<key>xpos</key>
<real>30</real>
<key>ypos</key>
<real>155</real>
</dict>
<key>98FFB671-15EA-49E0-AA9B-77570204157B</key>
<dict>
Expand Down Expand Up @@ -230,7 +299,7 @@ note: not all emojis are available in all languages.</string>
</dict>
</array>
<key>version</key>
<string>2.1.1</string>
<string>2.2.0</string>
<key>webaddress</key>
<string>https://github.com/fedecalendino/alfred-emoji-mate</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "Emoji Mate"
version = "2.1.1"
version = "2.2.0"
description = "Quickly search for emojis"
documentation = "https://github.com/fedecalendino/alfred-emoji-mate/blob/main/README.md"
homepage = "https://github.com/fedecalendino/alfred-emoji-mate"
Expand Down
17 changes: 9 additions & 8 deletions requirements.txt
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"
Binary file added screenshots/search by emoji.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/search by text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/usage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/emojis.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ def build():
yield alias, code


emojis = list(build())
emojis = list(build())
46 changes: 0 additions & 46 deletions src/main.py

This file was deleted.

29 changes: 29 additions & 0 deletions src/search_emoji.py
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()
29 changes: 29 additions & 0 deletions src/search_text.py
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()
37 changes: 37 additions & 0 deletions src/utils.py
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]
16 changes: 16 additions & 0 deletions tests/test_search_emoji.py
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")
2 changes: 1 addition & 1 deletion tests/test_main.py → tests/test_search_text.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pyflow.testing import WorklowTestCase

from main import main
from search_text import main


class TestMain(WorklowTestCase):
Expand Down

0 comments on commit 236fe85

Please sign in to comment.