Search code examples
pythondjangopython-requestscelery

How to pass today date in requests params Django


I have celery function which sends a request to API on every 5 minutes and get some JSON data.

I want to know how to pass today date in params to this request for example:

Full data will be 15k lines but if i pass today date to param I'll get only 1k lines.

tasks.py

def create_presence_info():
    payload = {'today_date': today} # this is an example idk what i should write there
    url = config('PRESENCE_INFO')
    response = requests.get(url, auth=UNICA_AUTH)

Solution

  • You can use the django.utils.timezone module to get the current date and time in the timezone specified in your Django settings, like the following:

    from django.utils import timezone
    
    def create_presence_info():
        today = timezone.localdate().strftime('%Y-%m-%d')
        payload = {'today_date': today}
        url = config('PRESENCE_INFO')
        response = requests.get(url, auth=UNICA_AUTH, params=payload)