Code snippet that reads CSV data from an web services and saves the data as a data table into the analysis.
Introduction
Below is snippet which reads CSV data from an web services and saves the data as a data table into the analysis.
Code Sample
# Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license. import clr clr.AddReference('System.Net') from System.IO import * from System.Net import HttpWebRequest, NetworkCredential from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings req = HttpWebRequest.Create("http://server-port/fileName.csv"") user_agent = 'individual user-agent' req.Method = "GET" req.UseDefaultCredentials = True readerSettings = TextDataReaderSettings() readerSettings.Separator = "," readerSettings.CultureName = "en-GB" rsp = req.GetResponse() dSource = TextFileDataSource(rsp.GetResponseStream(),readerSettings) tblfound="false" for table in Document.Data.Tables: if table.Name == "dataFromWebService": tblfound = "true" if tblfound == "false": Document.Data.Tables.Add("dataFromWebService",dSource) if tblfound == "true": Document.Data.Tables["dataFromWebService"].ReplaceData(dSource) rsp.Close ();
References
License: TIBCO BSD-Style License
Recommended Comments
There are no comments to display.