[spam][crazy][wrong] Genius Chatbot
!/usr/bin/env python3 while True: print('Hello, I am a genius chatbot.') print('Something is going wrong, and I cannot communicate, think or move.') print('') print('Luckily, through great effort, I have managed to let you input text to me:') user_text = input('What do you have to say? ') print('') print('Thank you for saying something.') print('If you would be so kind, I would like to store what you said somewhere, sp that I might some day try to comprehend it and reply.') print('Please add a storage backend to me.') print('Otherwise, here I go again!') print('')
# what is useful for goal of storing record of what was said? # maybe a file-backed list?
# draft of file-backed list # like everything, it needs to be refactored to use list and database abstractions import os class FileBackedList: def __init__(self, filename): try: self.file = open(filename, 'x+t') except FileExistsError: self.file = open(filename, 'r+t') self.offsets = [] while True: self.offsets.append(self.file.tell()) if self.file.readline() == '': break def __getitem__(self, offset): self.file.seek(self.offsets[offset]) return self.file.readline()[:-1] def append(self, line): self.file.seek(0, os.SEEK_END) endpos = self.file.tell() self.file.write(line + '\n') self.offsets.append(endpos) def __iadd__(self, other): assert type(other) is str return self.append(other) def __del__(self): self.file.close() # maybe it is not ok. it is a draft and has many errors.
###### it is wonderful! i can write what people say out to it, and what they say will be stored! i don't know what to do with what they said, anyway.
### we barely know what we're doing here. we want a simpler list, something that is not as confusing to look at. ### can we put the chatbot into a repository, and separate the list into another file? ######### just store what people say. I don't want to lose it. it's important.
participants (1)
-
Undiscussed Horrific Abuse, One Victim of Many