I'm trying to add a '/fact' command with Telebot module which returns a fact about dogs from API. However, I want it to return only one fact at a time, and a new one each time. I just don't know how to approach the issue. Here's my code:
@bot.message_handler(commands=['fact'])
def get_fact(message):
index = 0
while True:
facts = requests.get('https://dog-facts-api.herokuapp.com/api/v1/resources/dogs?index=' + str(index)).json()
f = facts[0]['fact']
index += 1
bot.send_message(message.chat.id, f)
OR:
@bot.message_handler(commands=['fact'])
def get_fact(message):
facts = requests.get('https://dog-facts-api.herokuapp.com/api/v1/resources/dogs/all').json()
f = list(facts)
iterator = iter(f)
bot.send_message(message.chat.id, iterator.__next__()['fact'])