0

I'm creating small project using rapid API to get daily report for COVID 19 .

import http.client ,time
from datetime import datetime

conn = http.client.HTTPSConnection("covid-19-data.p.rapidapi.com")

headers = {
    'x-rapidapi-host': "covid-19-data.p.rapidapi.com",
    'x-rapidapi-key': "xxxx"
    }
                                                                    # here I want to keep this date value is dynamic "today date"
conn.request("GET", "/report/country/name?date-format=YYYY-MM-DD&format=json&date=2020-06-12&name=uae", headers=headers)

res = conn.getresponse()
data = res.read()

how can I make the request dynamic with today value using datetime.today().strftime('%Y-%m-%d')

1 Answers1

0

You can pass the date as variable in the URL you are requesting for.

from datetime import datetime
today_date = datetime.today().strftime('%Y-%m-%d')
conn.request("GET", "/report/country/name?date-format=YYYY-MM-DD&format=json&date="+str(today_date)+"&name=uae", headers=headers)
Surajit Mitra
  • 414
  • 8
  • 15