SCRIPT_INT(
"import time
import requests
import json
import pandas as pd
import re
import urllib3
import math
from io import StringIO
from datetime import datetime, date,timedelta
from pandas.tseries.offsets import BDay
from urllib.parse import urlencode
from flask import json
def call_api(url, request_dict, post):
if post:
header = {'content-type':'application/json'}
resp = requests.post(url, data=json.dumps(request_dict), auth=('user', 'pass'), headers = header, verify=False)
else:
url = url + urlencode(request_dict)
resp = requests.get(url, auth=('user', 'pass'), verify=False)
status_code = resp.status_code
if status_code == 401:
raise ValueError('There is an error with the connection.\nLogin
failed. \nNot authorized. Please check your credentials and try
again.\nStatus code {}'.format(status_code))
elif status_code == 404:
raise ValueError('There is an error with the connection.\nCould not
connect to the server.\nStatus code {}'.format(status_code))
elif status_code == 200:
pass
else:
raise ValueError('There is an error with the connection.\nStatus
code {}'.format(status_code))
return resp
def getData (startDate, endDate, nodeName, Type, Id):
request_dict = [{
'hierarchy': 'Tableau',
'nodeName': nodeName,
'FilterId': Type,
'Id': Id ,
}]
url = 'https://sampleurl/startDate={0}&endDate={1}'
startDate = datetime.strptime(startDate, '%Y-%m-%d')
startDate = startDate.strftime ('%Y%m%d')
endDate = datetime.strptime(endDate, '%Y-%m-%d')
endDate = endDate.strftime ('%Y%m%d')
url = url.format(startDate, endDate)
resp = call_api(url, request_dict, True)
return resp.json ()
def get1D(startDate, endDate, nodeName, Type):
return getData (_arg1, _arg2, _arg3, _arg4, 1)"
,
ATTR([Start Date]),ATTR([End Date]),ATTR([Node Name], ATTR([Type]
)