-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsbuild.py
More file actions
executable file
·46 lines (39 loc) · 1.47 KB
/
wsbuild.py
File metadata and controls
executable file
·46 lines (39 loc) · 1.47 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
#!/usr/bin/python
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
import sys
from pathlib import Path
from contextlib import closing
from wsutils import Catalog
#---------------------------------------------------------------------------
class WordList:
def __init__(self, path):
self. path = path
def __iter__(self):
with self.path.open() as wordsIn:
for word in wordsIn:
word = word.replace('\n', '').lower()
if all('a' <= l <= 'z' or l == "'" for l in word):
yield word
#---------------------------------------------------------------------------
def main():
if not len(sys.argv) in (2, 3):
print("usage: wsbuild TEXT-FILE [CATALOG-FILE]")
sys.exit(1)
pathIn = Path(sys.argv[1])
if not pathIn.is_file():
print("File %s not found")
sys.exit(1)
if len(sys.argv) == 3:
pathOut = Path(sys.argv[2])
else:
pathOut = pathIn.with_suffix(".db")
words = WordList(pathIn)
with closing(Catalog.create(pathOut)) as cat:
for word in words:
cat.add(word)
if __name__ == "__main__":
main()
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------