tools/zulip-export/zulip-export: Fix how files are opened.

Instead of using codecs.open, use the builtin open in binary mode
and write data after encoding it in utf-8.
This commit is contained in:
Eklavya Sharma 2016-07-24 22:32:08 +05:30
parent df7dcdda5f
commit b08d6769c1
2 changed files with 2 additions and 4 deletions

View File

@ -62,7 +62,6 @@ bots/githook-post-receive
tools/deprecated/inject-messages/inject-messages tools/deprecated/inject-messages/inject-messages
tools/deprecated/review tools/deprecated/review
tools/update-deployment tools/update-deployment
tools/zulip-export/zulip-export
""".split() """.split()
exclude_scripts_py2 = [] # type: List[str] exclude_scripts_py2 = [] # type: List[str]

View File

@ -25,7 +25,6 @@ from __future__ import print_function
import sys import sys
import os.path import os.path
import optparse import optparse
import codecs
import time import time
import json import json
usage = """Export all messages on a given stream to a JSON dump. usage = """Export all messages on a given stream to a JSON dump.
@ -79,8 +78,8 @@ for msg in result['messages']:
messages.append(msg) messages.append(msg)
filename = "zulip-%s.json" % (options.stream,) filename = "zulip-%s.json" % (options.stream,)
f = codecs.open(filename, encoding='utf-8', mode="wb") f = open(filename, mode="wb")
f.write(json.dumps(messages, indent=0, sort_keys=False)) f.write(json.dumps(messages, indent=0, sort_keys=False).encode('utf-8'))
f.close() f.close()
print("%d messages exported to %s" % (len(messages), filename,)) print("%d messages exported to %s" % (len(messages), filename,))
sys.exit(0) sys.exit(0)