Created
April 7, 2020 14:50
-
-
Save rgs1/d9b62f827d941d20c1ed507078d1334a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.7 | |
import argparse | |
import json | |
import random | |
import string | |
def get_params(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
'num_keys', | |
type=int, | |
help='number of keys in the dict' | |
) | |
parser.add_argument( | |
'--key_size', | |
type=int, | |
default=10 | |
) | |
parser.add_argument( | |
'--value_size', | |
type=int, | |
default=10 | |
) | |
parser.add_argument( | |
'--json_indent', | |
type=int, | |
default=4 | |
) | |
return parser.parse_args() | |
def randstr(size): | |
return ''.join(random.choice(string.ascii_lowercase) for _ in range(size)) | |
def gen_blob(params): | |
d = {} | |
for _ in range(params.num_keys): | |
key = randstr(params.key_size) | |
val = randstr(params.value_size) | |
d[key] = val | |
return json.dumps(d, indent=params.json_indent) | |
if __name__ == '__main__': | |
print(gen_blob(get_params())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment