I am a bit new to python and its concepts. For my current project i need to do certain api calls at x rate/y mins. Regarding this i came across the concept of decorator and a python library for the same. Its called ratelimit and click here to go to its github link
The simplest example for this api is:
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
But i need to call this function call_api from another function
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()<end_time):
call_api(url)
I want the call to happen and want the arguments of decorator to be updates on runtime as the real values will be user input. But as per my understanding the decorator takes value before run time. So how can i pass dynamic value to the decorator.
Thanx in advance for helping