Mercurial > cosocket
changeset 36:d93c08dca64b
Conversation is now serialized to disk and appended to when new messages come in.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 27 Apr 2009 16:48:46 -0700 |
parents | 0e853a889c27 |
children | 979b247cba5d |
files | openwebchat.py |
diffstat | 1 files changed, 16 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/openwebchat.py Mon Apr 27 16:24:15 2009 -0700 +++ b/openwebchat.py Mon Apr 27 16:48:46 2009 -0700 @@ -9,7 +9,18 @@ import channels class Conversation(list): - pass + def __init__(self, fileobj): + list.__init__(self) + self.__file = fileobj + items = [] + for line in self.__file.readlines(): + items.append(eval(line)) + self[:] = items + + def append(self, item): + list.append(self, item) + self.__file.write('%s\n' % repr(item)) + self.__file.flush() class OpenWebChatServer(object): CONVERSATION_URL = re.compile('\/conversations\/([A-Za-z0-9_]+)') @@ -126,6 +137,9 @@ code = 404) if __name__ == '__main__': + if not os.path.exists('conversation.txt'): + open('conversation.txt', 'w').close() + server = OpenWebChatServer(('127.0.0.1', 8071), - Conversation()) + Conversation(open('conversation.txt', 'r+w'))) server.run()