import json

from django.core.management.base import BaseCommand

from evostream import EvoStreamException


class BaseEvoStreamCommand(BaseCommand):
    requires_system_checks = False

    silent_keys = ()

    def get_results(self, *args, **options):
        raise NotImplementedError()

    def format_results(self, results, verbosity):
        if verbosity > 1 or len(self.silent_keys) == 0:
            self.stdout.write(json.dumps(results, indent=1, sort_keys=True))
        else:
            for stream in results:
                for key in self.silent_keys:
                    self.stdout.write(key + ': ' + json.dumps(stream[key]) + '\n')

    def handle(self, verbosity, *args, **options):
        if not isinstance(verbosity, int):
            verbosity = int(verbosity)

        try:
            results = self.get_results(*args, **options)
        except EvoStreamException as ex:
            self.stderr.write(str(ex) + '\n')
            return

        if results is None:
            self.stdout.write('No data\n')
            return

        self.format_results(results, verbosity=verbosity)

@@ -496,18 +496,100 @@
     
-for stream
+if not isinstance(results, list):%0A                results = %5Bresults%5D%0A            for result
  in 
@@ -642,16 +642,58 @@
 t_keys:%0A
+                    if key in result:%0A    
         
@@ -746,22 +746,22 @@
 n.dumps(
-stream
+result
 %5Bkey%5D) +

fix format results