Что касается этого, я наткнулся на концепцию декоратора и библиотеку Python для того же самого.
Он называетсяratelimit, и нажмите здесь, чтобы перейти к ссылке на github.
Простейший пример этого API:
Код: Выделить всё
from ratelimit import rate_limited
import requests
MESSAGES=100
SECONDS= 3600
@rate_limited(MESSAGES, SECONDS)
def call_api(url):
response = requests.get(url)
if response.status_code != 200:
raise ApiError('Cannot call API: {}'.format(response.status_code))
return response
Код: Выделить всё
def send_message():
global MESSAGES
global SECONDS
MESSAGES=10
SECONDS=5
end_time=time.time()+60 #the end time is 60 seconds from the start time
while(time.time()
Подробнее здесь: [url]https://stackoverflow.com/questions/49259663/can-i-pass-a-dynamic-value-to-a-decorator-in-python[/url]
Мобильная версия