Skip to content
Advertisement

check if JSON response has an object

I’m trying to filter out if a JSON response has objects, and do something if it has.

My Problem is that even if it has objects, it won’t trigger the break.

Here is my code:

from tempmail import TempMail
import time
import pyperclip

email = TempMail()

email.generate_random_email_address()

print(email.login + '@' + email.domain)

pyperclip.copy(email.login + '@' + email.domain)

while True:
    if print(email.get_list_of_emails()) is None:
        print(email.get_list_of_emails())
        time.sleep(5)
    elif ['id'] in print(email.get_list_of_emails()):
        break

Advertisement

Answer

print(email.get_list_of_emails()) return None. This is why you never get the break. Try to remove the print

Try to change the code to something like the below (it will give you better visibility)

while True:
    data = email.get_list_of_emails()
    if data is None:
        print('data is None - going to sleep..')
        time.sleep(5)
    else:
        print('we have data!') 
        print(data)
        if ['id'] in data:
            print('got it!')
            break
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement