Table and Json formatters can write output to a file now.
Signed-off-by: Oleg Plakhotniuk <olegus8@gmail.com> closes #1412
This commit is contained in:
parent
36a4b78e67
commit
8875fad439
4 changed files with 39 additions and 8 deletions
|
|
@ -18,8 +18,6 @@
|
|||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from weboob.capabilities.base import NotAvailable, NotLoaded
|
||||
from weboob.tools.json import json
|
||||
|
||||
|
|
@ -54,7 +52,7 @@ class JsonFormatter(IFormatter):
|
|||
self.queue = []
|
||||
|
||||
def flush(self):
|
||||
print(json.dumps(self.queue, cls=Encoder))
|
||||
self.output(json.dumps(self.queue, cls=Encoder))
|
||||
|
||||
def format_dict(self, item):
|
||||
self.queue.append(item)
|
||||
|
|
@ -66,4 +64,9 @@ class JsonLineFormatter(IFormatter):
|
|||
The advantage is that it can be streamed.
|
||||
"""
|
||||
def format_dict(self, item):
|
||||
print(json.dumps(item, cls=Encoder))
|
||||
self.output(json.dumps(item, cls=Encoder))
|
||||
|
||||
def test():
|
||||
from .iformatter import formatter_test_output as fmt
|
||||
assert fmt(JsonFormatter, {'foo': 'bar'}) == '[{"foo": "bar"}]\n'
|
||||
assert fmt(JsonLineFormatter, {'foo': 'bar'}) == '{"foo": "bar"}\n'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue