24 lines
701 B
Python
24 lines
701 B
Python
#!/usr/bin/env python3
|
|
import sys
|
|
from smiley import smiley
|
|
from html.entities import codepoint2name
|
|
|
|
def retrohtml(line):
|
|
new_line_list = []
|
|
for char in line:
|
|
code_point = ord(char)
|
|
if code_point < 128:
|
|
new_line_list.append(char)
|
|
else:
|
|
try:
|
|
# Try to find a named HTML entity
|
|
new_line_list.append(f"&{codepoint2name[code_point]};")
|
|
except KeyError:
|
|
# And fall back to a numeric entity
|
|
new_line_list.append(f"&#{code_point};")
|
|
return "".join(new_line_list).strip()
|
|
|
|
for line in sys.stdin:
|
|
line=smiley.replace_emoji(line)
|
|
line=retrohtml(line)
|
|
print(line)
|