-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
34 lines (26 loc) · 1.11 KB
/
generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import json, argparse, time
import modules.schema as schema
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--t", "--type", help="Type of data as per the dataclass defined in schema.py. The default available options are: Blog, Product, User. You can define additional schemas in that file as well.")
parser.add_argument("--c", "--count", help="Number of records to create. Default is 10.")
parser.add_argument("--o", "--output", help="Filename to save the records as. The default is fake[Type]-[timestamp].json")
args = parser.parse_args()
if args.t is None:
exit("Error: Missing required type")
if args.c is None:
args.c = 10
class_ = getattr(schema, args.t)
rjson = []
if args.o is None:
filename = "fake" + args.t + "-" + str(time.time()) + ".json";
else:
filename = args.o
for _ in range(int(args.c)):
obj = class_()
rjson.append(obj.to_dict())
json_string = json.dumps(rjson)
with open(filename, "w") as file:
file.write(json_string)
if __name__ == "__main__":
main()