Changed file encoding (part 2)

This commit is contained in:
vylion 2020-10-26 22:59:24 +01:00
parent 11058f47a3
commit 64c117258d
2 changed files with 22 additions and 25 deletions

2
.gitignore vendored
View file

@ -3,3 +3,5 @@ __pycache__/*
misc/* misc/*
bkp/* bkp/*
test/* test/*
*log*

View file

@ -56,6 +56,18 @@ class Archivist(object):
file.close() file.close()
def load_vocab(self, tag): 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) filepath = self.chat_file(tag=tag, file="record", ext=self.chatext)
try: try:
file = open(filepath, 'r') file = open(filepath, 'r')
@ -90,25 +102,6 @@ class Archivist(object):
else: else:
return None 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): def chat_count(self):
count = 0 count = 0
directory = os.fsencode(self.chatdir) directory = os.fsencode(self.chatdir)
@ -139,11 +132,13 @@ class Archivist(object):
self.logger.exception(e) self.logger.exception(e)
raise e raise e
def update(self, oldext=None): def update(self):
for reader in self.readers_pass(): for reader in self.readers_pass():
try: if reader.vocab is None:
self.store(*reader.archive())
except Exception as e:
e.message = e.message[:1000]
self.logger.exception(e)
yield reader.cid() yield reader.cid()
else:
try:
self.store(*reader.archive())
except Exception as e:
self.logger.exception(e)
yield reader.cid()