Made it sort of a module, for easier inclusion in other scripts
This commit is contained in:
parent
a8ddc68a1d
commit
483da44672
3 changed files with 26 additions and 2 deletions
14
README.md
14
README.md
|
|
@ -5,6 +5,20 @@ Takes text with unicode emojis on standard input, spits out emojis replaced by
|
||||||
either classic smileys (`:-)`) or textual variants (`:joy:`) on standard
|
either classic smileys (`:-)`) or textual variants (`:joy:`) on standard
|
||||||
output.
|
output.
|
||||||
|
|
||||||
|
Alternatively, `import` it in your script and call `replace_emoji(<string>)`.
|
||||||
|
|
||||||
|
For example, start by adding this repo to your project (you're using git, I
|
||||||
|
presume):
|
||||||
|
```sh
|
||||||
|
git submodule add https://git.anduin.net/ltning/emoji_to_smiley.git smiley
|
||||||
|
```
|
||||||
|
then, in your code
|
||||||
|
```python
|
||||||
|
from smiley import smiley
|
||||||
|
for line in sys.stdin:
|
||||||
|
print(smiley.replace_emoji(line))
|
||||||
|
```
|
||||||
|
|
||||||
Needs
|
Needs
|
||||||
```
|
```
|
||||||
pip3.12 install emoji-data-python
|
pip3.12 install emoji-data-python
|
||||||
|
|
|
||||||
0
__init__.py
Normal file
0
__init__.py
Normal file
|
|
@ -1,9 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys
|
import sys
|
||||||
import emoji_data_python as ed
|
import emoji_data_python as ed
|
||||||
|
|
||||||
emoji_cp = {emoji.unified: emoji for emoji in ed.emoji_data}
|
emoji_cp = {emoji.unified: emoji for emoji in ed.emoji_data}
|
||||||
|
|
||||||
for line in sys.stdin:
|
def main():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def replace_emoji(line):
|
||||||
for e in list(set(ed.get_emoji_regex().findall(line))):
|
for e in list(set(ed.get_emoji_regex().findall(line))):
|
||||||
hexcp = format(ord(e),'x').upper()
|
hexcp = format(ord(e),'x').upper()
|
||||||
em = emoji_cp[hexcp]
|
em = emoji_cp[hexcp]
|
||||||
|
|
@ -15,4 +19,10 @@ for line in sys.stdin:
|
||||||
line=line.replace(e, ":" + em.short_name + ":")
|
line=line.replace(e, ":" + em.short_name + ":")
|
||||||
else:
|
else:
|
||||||
line=line.replace(e, "?")
|
line=line.replace(e, "?")
|
||||||
print(line,end='')
|
#print(line,end='')
|
||||||
|
return line.strip()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
for line in sys.stdin:
|
||||||
|
print(replace_emoji(line))
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue