-
Notifications
You must be signed in to change notification settings - Fork 17
/
proftoc.py
54 lines (47 loc) · 1.33 KB
/
proftoc.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
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
'''
Profanities file to C
@author Ph4r05
'''
import os
import sys
import argparse
import codecs
import locale
import struct
# Main executable code
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Profanities file to C', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('file', metavar='file', nargs='+', help='file to compute')
args = parser.parse_args()
if args.file is None or len(args.file) == 0:
parser.print_help()
sys.exit(-1)
# Wrap sys.stdout into a StreamWriter to allow writing unicode.
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
profans=[]
for curfile in args.file:
with open(curfile, 'r') as f:
lines = f.readlines()
# print "profanities[] = {"
for line in lines:
profans.append(line.strip())
# print "\"%s\"," % (line.strip())
# print "};"
pass
pass
padding=14
online=0
linebuff=""
for p in profans:
if online>8:
online=0
print linebuff
linebuff=""
nprof='"' + p + '",'
if (len(nprof)<padding):
nprof+=(' '*(padding-len(nprof)))
linebuff+=nprof
online+=1
pass