用 Python 開發(fā) emoji 表情查找程序

$ emo
------------------------------------------------------------------------------------
Type one or more emoji related words ...
End a word with a . if you want to select an emoji if there are multiple
matches, otherwise the first match will be picked. Type 'q' to exit.
> snake beer fire ninja
Copying ?? ?? ?? ?? to clipboard
------------------------------------------------------------------------------------
Type one or more emoji related words ...
End a word with a . if you want to select an emoji if there are multiple
matches, otherwise the first match will be picked. Type 'q' to exit.
> q
Bye
git clone [email protected]:PyBites-Open-Source/emojisearcher.git
cd emojisearcher
poetry install
poetry run emo
poetry使依賴項(xiàng)管理變得輕而易舉,最后一個(gè)命令(別名)實(shí)際上有效,因?yàn)槲覍⑵浞旁?/span>pyproject.toml文件中:[tool.poetry.scripts]
emo = "emojisearcher.script:main"
$ alias emo
alias emo='cd YOUR_PATH/emojisearcher && poetry run emo'
YOUR_PATH更改為項(xiàng)目的路徑。)poetry new,文件夾結(jié)構(gòu)從一開始就遵循了公認(rèn)的最佳做法。tests /文件夾中。emoji庫中的EMOJI_UNICODE常量來查找emoji表情:...
EMOJI_MAPPING = EMOJI_UNICODE[LANGUAGE]
...
def get_emojis_for_word(
word: str, emoji_mapping: dict[str, str] = EMOJI_MAPPING
) -> list[str]:
return [emo for name, emo in emoji_mapping.items() if word in name]
pyperclip復(fù)制到操作系統(tǒng)的剪貼板中:from pyperclip import copy
...
def copy_emojis_to_clipboard(matches: list[str]) -> None:
all_matching_emojis = ' '.join(matches)
print(f"Copying {all_matching_emojis} to clipboard")
copy(all_matching_emojis)
user_select_emoji函數(shù)進(jìn)入交互模式。SIGNAL_CHAR):如果用戶的搜索字符串以點(diǎn)(.)結(jié)尾,它將進(jìn)入交互模式。$ emo
------------------------------------------------------------------------------------
Type one or more emoji related words ...
End a word with a . if you want to select an emoji if there are multiple
matches, otherwise the first match will be picked. Type 'q' to exit.
> snake
Copying ?? to clipboard
------------------------------------------------------------------------------------
Type one or more emoji related words ...
End a word with a . if you want to select an emoji if there are multiple
matches, otherwise the first match will be picked. Type 'q' to exit.
> flag
Copying ?? to clipboard
------------------------------------------------------------------------------------
Type one or more emoji related words ...
End a word with a . if you want to select an emoji if there are multiple
matches, otherwise the first match will be picked. Type 'q' to exit.
> flag.
1 ??
2 ??
3 ??
4 ??
5 ??
6 ?
7 ??
8 ??
9 ?????
10 ??????
11 ??????
12 ??
13 ??
Select the number of the emoji you want: 12
Copying ?? to clipboard
------------------------------------------------------------------------------------
Type one or more emoji related words ...
End a word with a . if you want to select an emoji if there are multiple
matches, otherwise the first match will be picked. Type 'q' to exit.
> q
Bye
@ pytest.mark.parametrize非常好,可以使您的測試代碼更加簡潔。將代碼分解為更多的功能使其更可重用且更易于測試。 我測試了使用 @patch(“ builtins.input”,side_effect = ['a',10,2,'q']的交互模式模擬input的方法。side_effect中的列表包含將“double”input的參數(shù)。這等效于以下內(nèi)容(在鍵入tree之后。):
$ emo
------------------------------------------------------------------------------------
Type one or more emoji related words ...
End a word with a . if you want to select an emoji if there are multiple
matches, otherwise the first match will be picked. Type 'q' to exit.
> tree.
1 ??
2 ??
3 ??
4 ??
5 ??
Select the number of the emoji you want: a
a is not an integer.
1 ??
2 ??
3 ??
4 ??
5 ??
Select the number of the emoji you want: 10
10 is not a valid option.
1 ??
2 ??
3 ??
4 ??
5 ??
Select the number of the emoji you want: 2
Copying ?? to clipboard
------------------------------------------------------------------------------------
Type one or more emoji related words ...
End a word with a . if you want to select an emoji if there are multiple
matches, otherwise the first match will be picked. Type 'q' to exit.
> q
Bye
測試代碼時(shí),一種有用的技術(shù)是刪除所有常見的前導(dǎo)空白。您可以為此使用 textwrap.dedent,但是在這里我使用了替代的inspect.cleandoc。
toml文件中[tool.poetry]中的一些基本元數(shù)據(jù),發(fā)布到PyP非常簡單:poetry build
poetry publish
--repository of publish在測試PyPI上嘗試一下,看是否一切正常。)https://github.com/PyBites-Open-Source/emojisearcher更多閱讀
特別推薦

點(diǎn)擊下方閱讀原文加入社區(qū)會(huì)員
評論
圖片
表情
