-
Notifications
You must be signed in to change notification settings - Fork 0
/
runes.py
executable file
·45 lines (33 loc) · 955 Bytes
/
runes.py
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
#!/usr/bin/env python3
"""
Simple example::
"""
def getlines():
with open('UnicodeData.txt') as fp:
lines = fp.readlines()
return lines
def splitline(line:str):
'''Breaks the line on the semicolons
>>> splitline('a;b;c')
['a', 'c']
'''
return line.split(';')[:2]
def matchline(query, line):
query_set = set(query.upper().split())
line_set = set(line.split())
return query_set <= line_set
def matchlines(query, lines):
# results = []
for line in lines:
code, codepoint_name = splitline(line)
if matchline(query, codepoint_name):
# results.append((code, codepoint_name))
yield (code, codepoint_name)
# return results
def main(args):
query = ' '.join(args)
for code, codepoint_name in matchlines(query, getlines()):
print(chr(int(code, 16)), codepoint_name)
if __name__ == '__main__':
import sys
main(sys.argv[1:])