You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Chunk up large orders in planet orders request directly from a search.
Note: planet orders create would also have to be able to take in multiline input, as planet orders request would now output one line for each order chunk. How to do it is already demonstrated, we just have to work out the UI.
The script below is a slight alteration of the example script in #944. It demonstrates how to do a version of this:
importjsonimportclickclassMultiJSON(click.ParamType):
name='MultiJSON'defconvert(self, value, param, ctx) ->list:
ifisinstance(value, list):
conv=valueelse:
# read from raw json# skip this if value is a Path object or something elseifisinstance(value, str) and (value.startswith('{')
orvalue.startswith('[')):
print('hereh')
try:
conv=json.loads(value)
ifisinstance(conv, dict):
conv= [conv]
exceptjson.decoder.JSONDecodeError:
self.fail(
'JSON string is not valid JSON. Make sure the entire ''JSON string is single-quoted and string entries are ''double-quoted.')
# read from stdin or fileelse:
try:
withclick.open_file(value) asf:
conv= [json.loads(line) forlineinfifline]
exceptFileNotFoundError:
self.fail('File not found.')
exceptjson.decoder.JSONDecodeError:
stream='stdin'ifvalue=='-'else'JSON file'self.fail(f'{stream} does not contain valid JSON.')
ifnotlen(conv):
self.fail('JSON cannot be empty.')
returnconv@click.command()@click.option('--items', type=MultiJSON(), required=True)@click.option('--chunksize', type=int, default=5)defhello(items, chunksize):
click.echo(len(items))
# https://stackoverflow.com/a/312464defchunks(lst, n):
"""Yield successive n-sized chunks from lst."""foriinrange(0, len(lst), n):
yieldlst[i:i+n]
forchunkinchunks(items, chunksize):
click.echo(f'chunk: {len(chunk)}')
if__name__=='__main__':
hello()
The text was updated successfully, but these errors were encountered:
Chunk up large orders in planet orders request directly from a search.
Note: planet orders create would also have to be able to take in multiline input, as planet orders request would now output one line for each order chunk. How to do it is already demonstrated, we just have to work out the UI.
The script below is a slight alteration of the example script in #944. It demonstrates how to do a version of this:
ml.py
The text was updated successfully, but these errors were encountered: