I have Python Script which is correctly works in the Python environment. But I want run this script in the KNIME. I see some output table and don’t know how it correctly write…
from datetime import date, datetime, timedelta
import requests
import time
import json
#specify your range
start_date = date(2015, 5, 5)
end_date = date(2015, 5, 6)
list_of_dates = [start_date]
while start_date != end_date:
next_date = start_date + timedelta(days=1)
list_of_dates.append(next_date)
print(list_of_dates)
start_date = next_date
list_of_api_responses = {}
for date in list_of_dates :
date_param = date.isoformat()
print(date_param)
#Make API call
url = "myURL"
querystring = {"filter[review-date]": date_param,"instance":"myInstance"}
headers = {
'accept': "application/vnd.api+json",
'content-type': "application/vnd.api+json",
'authorization': "myToken"
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
##Append the new response to dict
list_of_api_responses[date_param]=response.text
##Create timelag between API calls
print("Delaying script")
time.sleep(8)
##Output the dict of JSON reponses
print(list_of_api_responses)
with open(‘output.txt’, ‘a’) as outfile:
json.dump(list_of_api_responses, outfile)