this code send generates a random json file of user ids provided and btw range is also given..
so this code outputs 50 jsons for each user.
import faker
import json
from faker import Faker
import random
from random import randint
import subprocess
import json
import os
#subprocess.call([""])
from pprint import pprint
ids= ('5cda','6cda')
fake = Faker('en_US')
for ind in ids:
cont = []
#Overall dictionary with first and user_ids
dct = {}
for idx in range(50):
sms = {
"id":"AB-asfgw",
"body": fake.text(),
"mime": fake.ean(),
"hashed": fake.ean(),
"pid": fake.ean(),
"user_id": ind,
"text": fake.sentence()
}
cont.append(sms)
dct['messages'] = cont
dct['user_id'] = ind
#print(dct)
f_name = '{}.json'.format(ind)
with open(f_name, 'w') as fp:
#Save the dictionary
json.dump(dct, fp, indent=4)
print('saved {}'.format(f_name))
auth = "authorization: token 1324"
file = "5cda.json"
fd=open("5cda.json")
json_content = fd.read()
fd.close()
subprocess.run(["grpcurl", "-plaintext","-H", auth,"-d",json_content,"-format","json","100.20.20.1:5000","api.Service/Method"])
this loop.py code loops the first code 20 times
from datetime import datetime
import faker
import json
from faker import Faker
import random
from random import randint
import subprocess
import json
import os
#subprocess.call([""])
from pprint import pprint
import subprocess
import sys
for i in range(20):
subprocess.call(['python','grploop1.py'])
i need to save the output of loop.py code for each loop. and store that json. example : we are looping the first code for 20 times in loop.py so ineed the output stored should be like 5cda1.json ........ 5cda20.json and 6cda1.json..... 6cda20.json
here we are giving two user ids ids= ('5cda','6cda')
so output would be total 40 json files.