|
import requests |
|
import datetime |
|
|
|
def fetch_data( |
|
lookback, |
|
span = 24, |
|
offset = 3, |
|
|
|
url = "https://visual-crossing-weather.p.rapidapi.com/history", |
|
headers = { |
|
"X-RapidAPI-Key": "12c5552beamshb548b266489323cp1c7cb2jsnf8b18027cebc", |
|
"X-RapidAPI-Host": "visual-crossing-weather.p.rapidapi.com" |
|
} |
|
): |
|
|
|
end_datetime = datetime.datetime.now() - datetime.timedelta(hours=lookback) |
|
start_datetime = end_datetime - datetime.timedelta(hours=(span+offset)) |
|
querystring = { |
|
"startDateTime": start_datetime.strftime("%Y-%m-%dT%H:%M:%S"), |
|
"aggregateHours": "1", |
|
"location": "Kolkata", |
|
"endDateTime": end_datetime.strftime("%Y-%m-%dT%H:%M:%S"), |
|
"unitGroup": "us", |
|
"dayStartTime": "00:00:00", |
|
"contentType": "csv", |
|
"dayEndTime": "23:59:00", |
|
"shortColumnNames": "0" |
|
} |
|
response = requests.get(url, headers=headers, params=querystring) |
|
|
|
|
|
if response.status_code == 200: |
|
|
|
return response |
|
else: |
|
print("Error:", response.status_code) |