Repository navigation
Expand file tree
/
Copy pathlesson_20.py
More file actions
160 lines (152 loc) · 4.66 KB
/
Copy pathlesson_20.py
File metadata and controls
160 lines (152 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Unicode
from unicodedata import *
a = "\N{GOTHIC LETTER AHSA}"
b = "x\u00b2"
c = "\U0001034A"
some_text = "Some \"bla-bla-bla\" text8). Awesome upside-down. \"It's just me>)\""
# print(f"{name(u'a')} looks like this: {a}")
# print(f"b looks like this: {b}")
# print(f"{name(u'c')} looks like {c}")
def upside_down_string(stringin):
"Returns string with reversed up symbols."
upd_string = []
symb_dict = {
'a': 'ɐ', #'U+0250'
'b': 'q',
'c': 'ɔ', #'(U+0254)'
'd': 'p',
'e': 'ǝ', #'(U+01DD)',
'f': 'ɟ', #'(U+025F)',
'g': 'ƃ', #'(U+0183)',
'h': 'ɥ', #'(U+0265)',
'i': 'ᴉ', #'(U+1D09)',
'j': 'ɾ', #'(U+027E)',
'k': 'ʞ', #'(U+029E)',
'l': 'l',
'm': 'ɯ', #'(U+026F)',
'n': 'u',
'o': 'o',
'p': 'd',
'q': 'b',
'r': 'ɹ', #'(U+0279)',
's': 's',
't': 'ʇ', #'(U+0287)',
'u': 'n',
'v': 'ʌ', #'(U+028C)',
'w': 'ʍ', #'(U+028D)',
'x': 'x',
'y': 'ʎ', #(U+028E)',
'z': 'z',
'A': '∀', #(U+2200),
'B': 'B',
'C': 'Ɔ', #(U+0186),
'D': 'D',
'E': 'Ǝ', #(U+018E),
'F': 'Ⅎ', #(U+2132),
'G': 'פ', #(U+05E4),
'H': 'H',
'I': 'I',
'J': 'ſ', #(U+017F),
'K': 'K',
'L': '˥', #(U+02E5),
'M': 'W',
'N': 'N',
'O': 'O',
'P': 'Ԁ', #(U+0500),
'Q': 'Q',
'R': 'R',
'S': 'S',
'T': '┴', #(U+2534),
'U': '∩', #(U+2229),
'V': 'Λ', #(U+039B),
'W': 'M',
'X': 'X',
'Y': '⅄', #(U+2144),
'Z': 'Z',
'0': '0',
'1': 'Ɩ', #(U+0196),
'2': 'ᄅ', #(U+1105),
'3': 'Ɛ', #(U+0190),
'4': 'ㄣ', #(U+3123),
'5': 'ϛ', #(U+03DB),
'6': '9',
'7': 'ㄥ', #(U+3125),
'8': '8',
'9': '6',
',': ',',
'.': '˙', #(U+02D9),
'?': '¿', #(U+00BF),
'!': '¡', #(U+00A1),
'"': ',,',
"'": ',',
"'": ',',
'(': ')',
')': '(',
'[': ']',
']': '[',
'{': '}',
'}': '{',
'<': '>',
'>': '<',
'&': '⅋', #'(U+214B)'
'_': '‾', #'(U+203E)'
' ': ' ',
'-': "-"
}
#check every symbol from input string for upside-down symbol in dict. If it exists append upside-down symbol to new dict.
for s in stringin:
if s in symb_dict:
#upd_string.append(symb_dict[s])
upd_string.insert(0, symb_dict[s])
else:
#upd_string.append('?')
upd_string.insert(0, symb_dict[s])
return ''.join(upd_string)
def smart_quotes(stringin):
"Returns string with smart quotes. Convert quotes to smart quotes."
smart_text = []
#Check all symbols for quotes
fquotes = False
for s in stringin:
if (s == '"') & fquotes:
fquotes = False
s = "\N{RIGHT DOUBLE QUOTATION MARK}"
elif s == '"':
fquotes = True
s = "\N{LEFT DOUBLE QUOTATION MARK}"
smart_text.append(s)
return ''.join(smart_text)
def smile_converter(stringin):
"Returns text with smiles. Convert combinations of 2 symbols from smiles_dict to Unicode smiles."
# a lot of smiles with Unicode codes here https://gist.github.com/endolith/157796
smiles_dict = {
':)': ['😀', 'Grinning Face'],
':8': ['😁', 'Grinning Face With Smiling Eyes'],
'3)': ['😂', 'Face With Tears of Joy'],
'8)': ['😃', 'Smiling Face With Open Mouth'],
'7)': ['😄', 'Smiling Face With Open Mouth and Smiling Eyes'],
'1)': ['😅', 'Smiling Face With Open Mouth and Cold Sweat'],
'3)': ['😆', 'Smiling Face With Open Mouth and Tightly-Closed Eyes'],
'0)': ['😇', 'Smiling Face With Halo'],
'>)': ['😈', 'Smiling Face With Horns'],
';)': ['😉', 'Winking Face']
}
text_with_smiles = []
#check input text for slices of symbols from smiles dictionary
n = 0
while n < len(stringin):
if n < len(stringin) - 2:
temp_slice = ''.join(stringin[n] + stringin[n + 1])
if temp_slice in smiles_dict:
s = smiles_dict[temp_slice][0]
n += 1
else:
s = stringin[n]
else:
s = stringin[n]
n += 1
text_with_smiles.append(s)
return ''.join(text_with_smiles)
print(f"Correct:\n{some_text}\nUpside-down and reversed:\n{upside_down_string(some_text)}")
b = f"Smart quotes text:\n{smart_quotes(some_text)}"
print(smile_converter(b))