成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

用 Python 開發 Emoji 表情查找程序

開發 后端
今天分享一個前幾天構建的小應用程序,用來從命令行搜索emoji表情符號。它可以通過OS命令行來完成,而且不必單擊任何東西即可獲得我的表情符號,更加便捷。

[[398183]]

本文轉載自微信公眾號「Python中文社區」,作者Python中文社區。轉載本文請聯系Python中文社區公眾號。

今天分享一個前幾天構建的小應用程序,用來從命令行搜索emoji表情符號。

它可以通過OS命令行來完成,而且不必單擊任何東西即可獲得我的表情符號,更加便捷。

該工具支持一次將多個匹配的表情符號復制到剪貼板。

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

至此,我的剪貼板上所有4個表情符號都寫好了,在鍵盤輸入Cmd + V即可。

是不是很酷?

安裝并運行程序包

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

poetry使依賴項管理變得輕而易舉,最后一個命令(別名)實際上有效,因為我將其放在pyproject.toml文件中:

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

您也可以通過添加以下shell別名來使調用命令更短(就像我在第一個示例中一樣):

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

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

文件夾結構

由于有了poetry new,文件夾結構從一開始就遵循了公認的最佳做法。

我喜歡將測試文件放在專用的tests /文件夾中。

我使用emoji庫中的EMOJI_UNICODE常量來查找emoji表情:

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

然后我使用pyperclip復制到操作系統的剪貼板中:

  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) 

感謝這個庫的作者AlSweigart,這是一個很酷的程序包。

如何查找多個表情符號?

在這種情況下,我通過user_select_emoji函數進入交互模式。

我想用一種創新的方式來觸發此交互模式,為此選擇了信號字符(SIGNAL_CHAR):如果用戶的搜索字符串以點(.)結尾,它將進入交互模式。

原因如下:

  1. $ emo 
  2.  
  3. ------------------------------------------------------------------------------------ 
  4. Type one or more emoji related words ... 
  5. End a word with a . if you want to select an emoji if there are multiple 
  6. matches, otherwise the first match will be picked. Type 'q' to exit. 
  7. > snake 
  8. Copying 🐍 to clipboard 
  9.  
  10. ------------------------------------------------------------------------------------ 
  11. Type one or more emoji related words ... 
  12. End a word with a . if you want to select an emoji if there are multiple 
  13. matches, otherwise the first match will be picked. Type 'q' to exit. 
  14. > flag 
  15. Copying 🏴 to clipboard 
  16.  
  17. ------------------------------------------------------------------------------------ 
  18. Type one or more emoji related words ... 
  19. End a word with a . if you want to select an emoji if there are multiple 
  20. matches, otherwise the first match will be picked. Type 'q' to exit. 
  21. > flag. 
  22. 1 🏴 
  23. 2 🏁 
  24. 3 📪 
  25. 4 📫 
  26. 5 🎌 
  27. 6 ⛳ 
  28. 7 📭 
  29. 8 📬 
  30. 9 🏴‍☠️ 
  31. 10 🏳️‍🌈 
  32. 11 🏳️‍⚧️ 
  33. 12 🚩 
  34. 13 🏳 
  35. Select the number of the emoji you want: 12 
  36. Copying 🚩 to clipboard 
  37.  
  38. ------------------------------------------------------------------------------------ 
  39. Type one or more emoji related words ... 
  40. End a word with a . if you want to select an emoji if there are multiple 
  41. matches, otherwise the first match will be picked. Type 'q' to exit. 
  42. > q 
  43. Bye 

鍵入“snake(蛇)”后出現的emoji不會出錯,但是對于“flag(旗幟)”,它默認選擇12個匹配項中的第一個(對于“heart(心臟)”,我們會得到130個匹配的表情符號!),這里我想手動選擇一個,因此鍵入點".",以做出進一步的選擇。

測試

還有幾件事:

@ pytest.mark.parametrize非常好,可以使您的測試代碼更加簡潔。

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

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

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

測試代碼時,一種有用的技術是刪除所有常見的前導空白。您可以為此使用textwrap.dedent,但是在這里我使用了替代的inspect.cleandoc。

上傳到PyPI

感謝toml文件中[tool.poetry]中的一些基本元數據,發布到PyP非常簡單:

  1. poetry build 
  2.  
  3. poetry publish 

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

如果您喜歡這個項目,請在Github上給它加星標,很高興能收到反饋。

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

 

責任編輯:武曉燕 來源: Python中文社區
相關推薦

2021-09-05 07:55:37

前端Emoji 表情

2017-12-18 11:16:31

iOS蘋果Bug

2022-07-27 11:22:44

Emoji圖片動圖

2015-06-26 11:14:09

Emoji 開發編程語言

2016-06-01 16:03:39

emoji圣經

2022-01-12 10:30:44

Windows 11Windows微軟

2025-05-27 08:00:00

Pythonemoji

2024-06-17 10:16:37

MySQLutf8mb4字節

2016-11-01 20:37:31

javascriptnode.jstypescript

2021-04-16 11:27:16

Python表情微信

2021-07-21 05:23:06

Linkerd Emoji.voto服務網格

2021-04-06 10:57:15

ChromeEmoji錯誤

2025-02-06 10:42:20

2024-03-27 08:41:09

Vue3Web應用emoji表情選擇器

2023-02-17 14:50:40

Windows 11微軟開發

2023-02-18 20:00:50

Windows 11Emoji 15

2015-06-23 10:07:31

密碼表情密碼

2021-07-16 05:31:42

Windows 11操作系統微軟

2024-04-29 08:22:42

2017-07-17 12:43:53

搜狗輸入法
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 黄色精品| 在线电影日韩 | 日韩欧美精品 | 全部免费毛片在线播放网站 | 色婷婷综合久久久久中文一区二区 | 成人亚洲片 | 日韩免费av | 91久操网| 日韩精品四区 | 久久亚洲国产精品日日av夜夜 | 色爽女 | 亚洲国产精品一区二区第一页 | 欧美日韩在线一区二区三区 | av网站观看 | 日本中文在线视频 | japanhd美女动 | 欧美在线色 | 久久久做 | 国产精品久久久久久久久久久久午夜片 | 精品视频在线一区 | a级毛片国产| 精品一区二区三区在线观看国产 | 国产一区二区a | 国产精品久久久久久吹潮 | 欧美日韩在线免费观看 | 亚洲美乳中文字幕 | 日本三级电影免费 | 国产精品视频导航 | av毛片免费| 一级黄色淫片 | 一级毛片色一级 | 久久91精品 | 精品福利视频一区二区三区 | 天堂色区| 久久久久久电影 | 古典武侠第一页久久777 | 无人区国产成人久久三区 | 成人18亚洲xxoo | 超碰最新在线 | 国产精品a久久久久 | 欧美男人天堂 |