mirror of
https://gitlab.com/vylion/velascobot.git
synced 2025-04-19 13:36:36 +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
40
archivist.py
40
archivist.py
|
@ -51,7 +51,7 @@ class Archivist(object):
|
|||
|
||||
if gen is not None:
|
||||
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.close()
|
||||
|
||||
|
@ -59,11 +59,12 @@ class Archivist(object):
|
|||
filepath = self.chat_file(tag=tag, file="record", ext=self.chatext)
|
||||
try:
|
||||
file = open(filepath, 'r')
|
||||
record = file.read()
|
||||
record = file.read().encode().decode('utf-8')
|
||||
file.close()
|
||||
return record
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
self.logger.error("Vocabulary file {} not found.".format(filepath))
|
||||
self.logger.exception(e)
|
||||
return None
|
||||
|
||||
def load_reader(self, tag):
|
||||
|
@ -139,29 +140,10 @@ class Archivist(object):
|
|||
raise e
|
||||
|
||||
def update(self, oldext=None):
|
||||
failed = []
|
||||
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:
|
||||
self.logger.info("Updating chat " + filename)
|
||||
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:
|
||||
failed.append(filename)
|
||||
self.logger.error("Found the following error when trying to update:")
|
||||
self.logger.exception(e)
|
||||
else:
|
||||
continue
|
||||
return failed
|
||||
for reader in self.readers_pass():
|
||||
try:
|
||||
self.store(*reader.archive())
|
||||
except Exception as e:
|
||||
e.message = e.message[:1000]
|
||||
self.logger.exception(e)
|
||||
yield reader.cid()
|
||||
|
|
|
@ -80,7 +80,7 @@ class Generator(object):
|
|||
|
||||
def dumps(self):
|
||||
# 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):
|
||||
# Loads the cache dictionary from a JSON-formatted string
|
||||
|
|
Loading…
Reference in a new issue