-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfortune.py
More file actions
33 lines (25 loc) · 825 Bytes
/
fortune.py
File metadata and controls
33 lines (25 loc) · 825 Bytes
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
from Utils import Files
import time, random
class FortuneTools:
def __init__(self):
self.fortunefile = '/home/vengle/projects/Notes/fortunes.txt'
self.fortunes = dict()
def LoadFortunes(self):
f = Files()
f.read_file(self.fortunefile)
myfortune = ''
i = 4000
for line in f.data:
x = line.strip()
if x == '%':
self.fortunes[i] = myfortune
i += 1
myfortune = ''
else:
myfortune = myfortune + line + "\n"
def GetRandom(self):
mylist = self.fortunes.keys()
mykey = random.choice (mylist)
return self.fortunes[mykey]
def FormatTime(self,t):
return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t))