forked from BrachystochroneSD/AnnouncementWindow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GamelogReader.py
50 lines (41 loc) · 1.33 KB
/
GamelogReader.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
import Config
import os, io
from Announcements import announcement
import re
class gamelog(object):
def __init__(self):
self.file = None
def connect(self):
if os.path.isfile(Config.settings.get_gamelog_path()):
self.file = io.open(Config.settings.get_gamelog_path(), 'r', encoding='cp437')
self.file.seek(0, 2) # Move to the end of the file
return True
else:
self.file = None
return False
def get_new_announcements(self, list_=None):
if list_ is None:
list_ = self.file
new = []
if self.file:
for newline in list_:
s = newline.strip()
if len(s) != 0:
new.append(announcement(s))
return new
def get_old_announcements(self):
lines = []
if self.file:
self.file.seek(0, 0)
exp = re.compile('\*\* Loading Fortress \*\*')
for line in self.file:
if exp.match(line):
lines = []
lines.append(line)
return self.get_new_announcements(list_=lines)
def new(self):
return self.get_new_announcements()
def get_all_announcements(self):
if self.file:
self.file.seek(0, 0)
return self.get_new_announcements()