-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlib_comment.py
executable file
·57 lines (48 loc) · 1.4 KB
/
lib_comment.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
55
56
57
#!/usr/bin/env python3
from sys import argv
import sqlite3
from datetime import datetime
from MarkovChain import MarkovChain
from config import COMMENT_FILE, MARKOV_DB, MIN_LEN, LOG_FILE
mc = MarkovChain(MARKOV_DB)
def makeDatabase():
with open(COMMENT_FILE, 'r') as f:
mc.generateDatabase(f.read())
mc.dumpdb()
def printComments(qty):
for i in range(0, qty):
x = mc.generateString()
while len(x) < MIN_LEN:
x = mc.generateString()
print(str(i) + " - " + x[:140])
def singleComment():
comment = mc.generateString()
while len(comment) < MIN_LEN:
comment = mc.generateString()
return comment
def singleCommentSeed(seed):
up_seed = str(seed).upper()
comment = mc.generateStringWithSeed(up_seed)
while len(comment) < MIN_LEN:
comment = mc.generateStringWithSeed(up_seed)
return comment
def logError(message):
now = datetime.now().strftime('%y-%m-%d %H:%M:%S')
output = now + ": " +str(message)
with open(LOG_FILE,'a') as f:
f.write(output)
def usage():
print("Usage:\t" + argv[0] + " comment [N# of comments]"\
"\n\t"+argv[0]+" makedatabase" )
if __name__ == "__main__":
qty = 10
if 'makedatabase' in argv:
makeDatabase()
elif 'comment' in argv:
try:
qty = int(argv[2])
except:
pass
printComments(qty)
else:
usage()