keiffster / program-y

Python 3.x based AIML 2.0 Chatbot interpreter, framework, related programs and knowledge files
https://keiffster.github.io/program-y/
Other
350 stars 135 forks source link

Conversation file - Unicode issue + csv format suggestion... #91

Closed seghcder closed 7 years ago

seghcder commented 7 years ago

In bot.py I got an exception when the response included unicode. Added: encoding="utf-8" to the file open -


    def log_question_and_answer(self, clientid, question, answer):
        filename = self.brain.configuration.files.aiml_files.conversation
        if filename is not None:
            with open(filename, "a+",**encoding="utf-8"**) as file:
                timestamp = "{:%Y-%m-%d %H:%M:%S}".format(datetime.datetime.now())
                output = "%s - %s - Question[%s] - Response[%s]\n"%(timestamp, clientid, question, answer)
                file.write(output)

Suggestion: As one of the tasks of the botmaster is to review questions and responses, could the output of the conversation file be (optionally) CSV? This would allow better import into Excel or other tool (but would need some good escaping of quote chars etc!)

keiffster commented 7 years ago

Encoding will be added in next release, I’ll run it through all file opens for safe measure

Csv output has been asked for a couple of times and I’ve found a couple of good python csv libraries which support native excel formats and good quoting, so watch this space....

keiffster commented 7 years ago

2 changes going into development, one already there. All open files now opened with encoding set

errors, duplicates and conversation files can now be either txt or csv. Configuration driven. This will probably get pushed tonight and I'll update the wiki with the config changes in the morning

keiffster commented 7 years ago

Changes pushed to development branch and wiki updated

keiffster commented 7 years ago

Is this working for you now, going to merge to master over the next few days and will form v1.1 release