Как сделать постоянное обновление api | Python requests
Не понимаю как сделать постоянное обновление api. при вводе команды постоянно выдаёт одну цитату вместо новой. (если перезапустить скрипт то выдается новая)
import telebot
import requests
import logging
logger = telebot.logger
telebot.logger.setLevel(logging.DEBUG)
client = telebot.TeleBot('Token')
url = 'https://favqs.com/api/qotd'
response = requests.get(url)
jsonResponse = response.json()
citata = jsonResponse["quote"]["body"]
author = jsonResponse["quote"]["author"]
@client.message_handler(commands=['quote'])
def quote(message):
client.send_message(message.chat.id, citata + f'\n Author: ' + author)
client.polling(none_stop=True, interval=0)
Ответы (1 шт):
Автор решения: heevik
→ Ссылка
не буду удалять, оставлю вдруг кто-то как я затупит и не поймет что нужно было просто это в функцию запихнуть, хаха
def quote(message):
response = requests.get(url)
jsonResponse = response.json()
citata = jsonResponse["quote"]["body"]
author = jsonResponse["quote"]["author"]
client.send_message(message.chat.id, citata + f'\n Author: ' + author)