mirror of
https://gitlab.com/vylion/velascobot.git
synced 2025-04-19 21:46:35 +02:00
Changed file encoding (part 1)
This commit is contained in:
parent
66f3280741
commit
11058f47a3
2 changed files with 12 additions and 30 deletions
34
archivist.py
34
archivist.py
|
@ -51,7 +51,7 @@ class Archivist(object):
|
||||||
|
|
||||||
if gen is not None:
|
if gen is not None:
|
||||||
chat_record = self.chat_file(tag=tag, file="record", ext=self.chatext)
|
chat_record = self.chat_file(tag=tag, file="record", ext=self.chatext)
|
||||||
file = open(chat_record, 'w')
|
file = open(chat_record, 'w', encoding="utf-16")
|
||||||
file.write(gen)
|
file.write(gen)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
@ -59,11 +59,12 @@ class Archivist(object):
|
||||||
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')
|
||||||
record = file.read()
|
record = file.read().encode().decode('utf-8')
|
||||||
file.close()
|
file.close()
|
||||||
return record
|
return record
|
||||||
except Exception:
|
except Exception as e:
|
||||||
self.logger.error("Vocabulary file {} not found.".format(filepath))
|
self.logger.error("Vocabulary file {} not found.".format(filepath))
|
||||||
|
self.logger.exception(e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def load_reader(self, tag):
|
def load_reader(self, tag):
|
||||||
|
@ -139,29 +140,10 @@ class Archivist(object):
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def update(self, oldext=None):
|
def update(self, oldext=None):
|
||||||
failed = []
|
for reader in self.readers_pass():
|
||||||
remove = False
|
|
||||||
if not oldext:
|
|
||||||
oldext = self.chatext
|
|
||||||
remove = True
|
|
||||||
|
|
||||||
directory = os.fsencode(self.chatdir)
|
|
||||||
for file in os.listdir(directory):
|
|
||||||
filename = os.fsdecode(file)
|
|
||||||
if filename.endswith(oldext):
|
|
||||||
try:
|
try:
|
||||||
self.logger.info("Updating chat " + filename)
|
self.store(*reader.archive())
|
||||||
scribe = self.recall(filename)
|
|
||||||
if scribe is not None:
|
|
||||||
scribe.store(scribe.parrot.dumps())
|
|
||||||
self.wakeParrot(scribe.cid())
|
|
||||||
self.logger.info("--- Update done: " + scribe.title())
|
|
||||||
if remove:
|
|
||||||
os.remove(filename)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
failed.append(filename)
|
e.message = e.message[:1000]
|
||||||
self.logger.error("Found the following error when trying to update:")
|
|
||||||
self.logger.exception(e)
|
self.logger.exception(e)
|
||||||
else:
|
yield reader.cid()
|
||||||
continue
|
|
||||||
return failed
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ class Generator(object):
|
||||||
|
|
||||||
def dumps(self):
|
def dumps(self):
|
||||||
# Dumps the cache dictionary into a JSON-formatted string
|
# Dumps the cache dictionary into a JSON-formatted string
|
||||||
return json.dumps(self.cache)
|
return json.dumps(self.cache, ensure_ascii=False)
|
||||||
|
|
||||||
def loads(dump):
|
def loads(dump):
|
||||||
# Loads the cache dictionary from a JSON-formatted string
|
# Loads the cache dictionary from a JSON-formatted string
|
||||||
|
|
Loading…
Reference in a new issue