Example #1
0
 def handle(self, *args, **options):
     dd = strict_get_data_download(options['dataset'])
     if options['format'] == 'csv':
         iterator = generate_streaming_csv(dd.generate_csv_rows())
     else:
         assert options['format'] == 'json'
         iterator = generate_streaming_json(dd.generate_json_rows())
     self.stdout.ending = ''
     for string in iterator:
         self.stdout.write(string)
Example #2
0
 def handle(self, *args, **options):
     username: Optional[str] = options["user"]
     user = JustfixUser.objects.get(
         username=username) if username else AnonymousUser()
     dd = strict_get_data_download(options["dataset"])
     if options["format"] == "csv":
         iterator = generate_streaming_csv(dd.generate_csv_rows(user))
     else:
         assert options["format"] == "json"
         iterator = generate_streaming_json(dd.generate_json_rows(user))
     self.stdout.ending = ""
     for string in iterator:
         self.stdout.write(string)
Example #3
0
def get_csv_snippet(rows: Iterator[List[Any]]) -> str:
    return "".join(
        list(
            generate_streaming_csv(
                itertools.islice(rows, 0, SNIPPET_MAX_ROWS + 1))))
Example #4
0
def test_generate_streaming_csv_works():
    g = generate_streaming_csv(rows)
    assert next(g) == "a,b,c\r\n"
    assert next(g) == "d,e,f\u2026\r\n"
    with pytest.raises(StopIteration):
        next(g)