mirror of
https://gitlab.com/vylion/velascobot.git
synced 2025-04-19 13:36:36 +02:00
Changed file encoding (part 2)
This commit is contained in:
parent
11058f47a3
commit
64c117258d
2 changed files with 22 additions and 25 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,3 +3,5 @@ __pycache__/*
|
|||
misc/*
|
||||
bkp/*
|
||||
test/*
|
||||
*log*
|
||||
|
||||
|
|
37
archivist.py
37
archivist.py
|
@ -56,6 +56,18 @@ class Archivist(object):
|
|||
file.close()
|
||||
|
||||
def load_vocab(self, tag):
|
||||
filepath = self.chat_file(tag=tag, file="record", ext=self.chatext)
|
||||
try:
|
||||
file = open(filepath, 'r', encoding="utf-16")
|
||||
record = file.read()
|
||||
file.close()
|
||||
return record
|
||||
except Exception as e:
|
||||
self.logger.error("Vocabulary file {} not found.".format(filepath))
|
||||
self.logger.exception(e)
|
||||
return None
|
||||
|
||||
def load_vocab_old(self, tag):
|
||||
filepath = self.chat_file(tag=tag, file="record", ext=self.chatext)
|
||||
try:
|
||||
file = open(filepath, 'r')
|
||||
|
@ -90,25 +102,6 @@ class Archivist(object):
|
|||
else:
|
||||
return None
|
||||
|
||||
def load_reader_old(self, filename):
|
||||
file = open(self.chatdir + filename, 'rb')
|
||||
reader = None
|
||||
try:
|
||||
reader, vocab = Reader.FromFile(pickle.load(file), self)
|
||||
self.logger.info("Unpickled {}{}".format(self.chatdir, filename))
|
||||
except pickle.UnpicklingError:
|
||||
file.close()
|
||||
file = open(self.chatdir + filename, 'r')
|
||||
try:
|
||||
scribe = Reader.FromFile(file.read(), self)
|
||||
self.logger.info("Read {}{} text file".format(self.chatdir, filename))
|
||||
except Exception as e:
|
||||
self.logger.error("Failed reading {}{}".format(self.chatdir, filename))
|
||||
self.logger.exception(e)
|
||||
raise e
|
||||
file.close()
|
||||
return scribe
|
||||
|
||||
def chat_count(self):
|
||||
count = 0
|
||||
directory = os.fsencode(self.chatdir)
|
||||
|
@ -139,11 +132,13 @@ class Archivist(object):
|
|||
self.logger.exception(e)
|
||||
raise e
|
||||
|
||||
def update(self, oldext=None):
|
||||
def update(self):
|
||||
for reader in self.readers_pass():
|
||||
if reader.vocab is None:
|
||||
yield reader.cid()
|
||||
else:
|
||||
try:
|
||||
self.store(*reader.archive())
|
||||
except Exception as e:
|
||||
e.message = e.message[:1000]
|
||||
self.logger.exception(e)
|
||||
yield reader.cid()
|
||||
|
|
Loading…
Reference in a new issue