日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線(xiàn)溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
用Python開(kāi)發(fā)Emoji表情查找程序

本文轉(zhuǎn)載自微信公眾號(hào)「Python中文社區(qū)」,作者Python中文社區(qū)。轉(zhuǎn)載本文請(qǐng)聯(lián)系Python中文社區(qū)公眾號(hào)。

創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括昌邑網(wǎng)站建設(shè)、昌邑網(wǎng)站制作、昌邑網(wǎng)頁(yè)制作以及昌邑網(wǎng)絡(luò)營(yíng)銷(xiāo)策劃等。多年來(lái),我們專(zhuān)注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,昌邑網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶(hù)以成都為中心已經(jīng)輻射到昌邑省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶(hù)的支持與信任!

今天分享一個(gè)前幾天構(gòu)建的小應(yīng)用程序,用來(lái)從命令行搜索emoji表情符號(hào)。

它可以通過(guò)OS命令行來(lái)完成,而且不必單擊任何東西即可獲得我的表情符號(hào),更加便捷。

該工具支持一次將多個(gè)匹配的表情符號(hào)復(fù)制到剪貼板。

 
 
 
  1. $ emo
  2. ------------------------------------------------------------------------------------
  3. Type one or more emoji related words ...
  4. End a word with a . if you want to select an emoji if there are multiple
  5. matches, otherwise the first match will be picked. Type 'q' to exit.
  6. > snake beer fire ninja
  7. Copying    ???? to clipboard
  8. ------------------------------------------------------------------------------------
  9. Type one or more emoji related words ...
  10. End a word with a . if you want to select an emoji if there are multiple
  11. matches, otherwise the first match will be picked. Type 'q' to exit.
  12. > q
  13. Bye

至此,我的剪貼板上所有4個(gè)表情符號(hào)都寫(xiě)好了,在鍵盤(pán)輸入Cmd + V即可。

是不是很酷?

安裝并運(yùn)行程序包

 
 
 
  1. git clone git@github.com:PyBites-Open-Source/emojisearcher.git
  2. cd emojisearcher
  3. poetry install
  4. poetry run emo

poetry使依賴(lài)項(xiàng)管理變得輕而易舉,最后一個(gè)命令(別名)實(shí)際上有效,因?yàn)槲覍⑵浞旁趐yproject.toml文件中:

 
 
 
  1. [tool.poetry.scripts]
  2. emo = "emojisearcher.script:main"

您也可以通過(guò)添加以下shell別名來(lái)使調(diào)用命令更短(就像我在第一個(gè)示例中一樣):

 
 
 
  1. $ alias emo
  2. alias emo='cd YOUR_PATH/emojisearcher && poetry run emo'

(將YOUR_PATH更改為項(xiàng)目的路徑。)

文件夾結(jié)構(gòu)

由于有了poetry new,文件夾結(jié)構(gòu)從一開(kāi)始就遵循了公認(rèn)的最佳做法。

我喜歡將測(cè)試文件放在專(zhuān)用的tests /文件夾中。

庫(kù)

我使用emoji庫(kù)中的EMOJI_UNICODE常量來(lái)查找emoji表情:

 
 
 
  1. ...
  2. EMOJI_MAPPING = EMOJI_UNICODE[LANGUAGE]
  3. ...
  4. def get_emojis_for_word(
  5.     word: str, emoji_mapping: dict[str, str] = EMOJI_MAPPING
  6. ) -> list[str]:
  7.     return [emo for name, emo in emoji_mapping.items() if word in name]

然后我使用pyperclip復(fù)制到操作系統(tǒng)的剪貼板中:

 
 
 
  1. from pyperclip import copy
  2. ...
  3. def copy_emojis_to_clipboard(matches: list[str]) -> None:
  4.     all_matching_emojis = ' '.join(matches)
  5.     print(f"Copying {all_matching_emojis} to clipboard")
  6.     copy(all_matching_emojis)

感謝這個(gè)庫(kù)的作者AlSweigart,這是一個(gè)很酷的程序包。

如何查找多個(gè)表情符號(hào)?

在這種情況下,我通過(guò)user_select_emoji函數(shù)進(jìn)入交互模式。

我想用一種創(chuàng)新的方式來(lái)觸發(fā)此交互模式,為此選擇了信號(hào)字符(SIGNAL_CHAR):如果用戶(hù)的搜索字符串以點(diǎn)(.)結(jié)尾,它將進(jìn)入交互模式。

原因如下:

 
 
 
  1. $ emo
  2. ------------------------------------------------------------------------------------
  3. Type one or more emoji related words ...
  4. End a word with a . if you want to select an emoji if there are multiple
  5. matches, otherwise the first match will be picked. Type 'q' to exit.
  6. > snake
  7. Copying  to clipboard
  8. ------------------------------------------------------------------------------------
  9. Type one or more emoji related words ...
  10. End a word with a . if you want to select an emoji if there are multiple
  11. matches, otherwise the first match will be picked. Type 'q' to exit.
  12. > flag
  13. Copying  to clipboard
  14. ------------------------------------------------------------------------------------
  15. Type one or more emoji related words ...
  16. End a word with a . if you want to select an emoji if there are multiple
  17. matches, otherwise the first match will be picked. Type 'q' to exit.
  18. > flag.
  19. 9 ??
  20. 10 ??
  21. 11 ???
  22. 12 
  23. 13 
  24. Select the number of the emoji you want: 12
  25. Copying  to clipboard
  26. ------------------------------------------------------------------------------------
  27. Type one or more emoji related words ...
  28. End a word with a . if you want to select an emoji if there are multiple
  29. matches, otherwise the first match will be picked. Type 'q' to exit.
  30. > q
  31. Bye

鍵入“snake(蛇)”后出現(xiàn)的emoji不會(huì)出錯(cuò),但是對(duì)于“flag(旗幟)”,它默認(rèn)選擇12個(gè)匹配項(xiàng)中的第一個(gè)(對(duì)于“heart(心臟)”,我們會(huì)得到130個(gè)匹配的表情符號(hào)!),這里我想手動(dòng)選擇一個(gè),因此鍵入點(diǎn)".",以做出進(jìn)一步的選擇。

測(cè)試

還有幾件事:

@ pytest.mark.parametrize非常好,可以使您的測(cè)試代碼更加簡(jiǎn)潔。

將代碼分解為更多的功能使其更可重用且更易于測(cè)試。

我測(cè)試了使用@patch(“ builtins.input”,side_effect = ['a',10,2,'q']的交互模式模擬input的方法。side_effect中的列表包含將“double” input的參數(shù)。這等效于以下內(nèi)容(在鍵入tree之后。):

 
 
 
  1. $ emo
  2. ------------------------------------------------------------------------------------
  3. Type one or more emoji related words ...
  4. End a word with a . if you want to select an emoji if there are multiple
  5. matches, otherwise the first match will be picked. Type 'q' to exit.
  6. > tree.
  7. Select the number of the emoji you want: a
  8. a is not an integer.
  9. Select the number of the emoji you want: 10
  10. 10 is not a valid option.
  11. Select the number of the emoji you want: 2
  12. Copying  to clipboard
  13. ------------------------------------------------------------------------------------
  14. Type one or more emoji related words ...
  15. End a word with a . if you want to select an emoji if there are multiple
  16. matches, otherwise the first match will be picked. Type 'q' to exit.
  17. > q
  18. Bye

測(cè)試代碼時(shí),一種有用的技術(shù)是刪除所有常見(jiàn)的前導(dǎo)空白。您可以為此使用textwrap.dedent,但是在這里我使用了替代的inspect.cleandoc。

上傳到PyPI

感謝toml文件中[tool.poetry]中的一些基本元數(shù)據(jù),發(fā)布到PyP非常簡(jiǎn)單:

 
 
 
  1. poetry build
  2. poetry publish

(首先使用--repository of publish在測(cè)試PyPI上嘗試一下,看是否一切正常。)

如果您喜歡這個(gè)項(xiàng)目,請(qǐng)?jiān)贕ithub上給它加星標(biāo),很高興能收到反饋。

https://github.com/PyBites-Open-Source/emojisearcher


當(dāng)前題目:用Python開(kāi)發(fā)Emoji表情查找程序
本文URL:http://www.5511xx.com/article/dpphoho.html