-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTermCommands.py
More file actions
76 lines (68 loc) · 2.41 KB
/
TermCommands.py
File metadata and controls
76 lines (68 loc) · 2.41 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
#Creates dictionary and list for t&c.txt for future reference.
temp = open('t&c.txt', encoding = "utf8")
data = temp.readlines()
temp.close()
termlist = []
for line in data:
if not line[0].isdigit() :
continue
line = line.strip().split('. ',1)
termlist.append(line)
termdict = {}
for entry in termlist:
termdict[int(entry[0])] = entry[1]
commandlist = [['!t', 'search term by number'],['!ts', 'search through terms using a keyword'],['!tr', 'get random term'],
['!r','recall the five most recent terms'],['!link','see the entire list'],['!ref','shows terms referenced by previously by me']]
searchlist = []
def term(msg):
global searchlist
searchlist = []
if msg.isdigit():
searchlist.append(int(msg))
if int(msg) <= len(termlist):
return ('Term number %i: %s' % (int(msg),termdict[int(msg)]))
def termSearch(msg):
global searchlist
searchlist = []
output = ""
for entry in termlist:
if msg.lower() in entry[1].lower() :
searchlist.append(int(entry[0]))
if len(searchlist) > 10:
return ('Be more specific.')
if len(searchlist) == 0:
return ('No terms found.')
for query in searchlist :
output += ('Term number %i: %s \n' % (query,termdict[query]))
return output
def recent():
i = 5
output = ""
while i >= 0 :
output += ('Term number %i: %s \n' % ((len(termlist)-i),termdict[len(termlist)-i]))
i -= 1
return output
def help():
output = ""
for entry in commandlist:
output += ('Use "%s" to %s! \n' % (entry[0],entry[1]))
return output
def reference():
global searchlist
output = ""
referencelist = []
for query in searchlist:
if termdict[query][0] == "^" :
output += ('Term number %i: %s \n' % ((query-1),termdict[query-1]))
referencelist.append(query-1)
if "see: ".lower() in termdict[query].lower():
refstring = ""
reflocation = termdict[query].find("see: ")
for i in termdict[query][(reflocation+4):]:
if i.isdigit():
refstring += i
output += ('Term number %i: %s \n' % ((int(refstring),termdict[int(refstring)])))
searchlist = referencelist[:]
if output == "":
return "There is nothing to reference."
return output