Hello everybody,
I have a json file which stores information for different people, which looks like this:
I have a json file which stores information for different people, which looks like this:
{ "person": [ { {"id": "1", "name": "Geroge" "status": "unsent" }, {"id": "2", "name": "Tim" "status": "unsent" } ] }Everytime my script get's executed I want to select a random person. Once the person has been selected it should change the value "status" to "sent"
def random_operation(): with open('config.json', "r") as fp: data = json.load(fp) person = data["person"] random_index = randint(0, len(person)-1) index = (operation[random_index]['name'] print(index) with open('config.json', "w") as fx: data['person'][int(random_index)]['status'] = "sent" json.dump(data, fx)This works fine. Now I want that everytime the script gets executed it only selects people who have status = unsent. When it randomly selects a person whose status is unsent it should do something and if the script randomly selects a person whose status is sent it should repeat until it finds a person with status = unsent. Once every status has been changed to sent (and no one has status= unsent) all statuses should get reset to unsnet. I'm not sure how to do this. I've tried with While True but that trapped me in an infinite-loop...