private static void Main(string[] args) { Setup(args); if (HandleHelp()) { return; } if (HandleErrors()) { return; } string filename = arguments.Filename; IQuandlRequest request = arguments.Request; if (request != null) { Print("Submitting request to Quandl..."); RequestToFile(filename, request); Print("Request complete."); } else { Print("No request object specified"); } WaitForExit(); return; }
private string Get(IQuandlRequest request) { string data = string.Empty; using (WebClient client = new WebClient()) { string requestString = request.ToRequestString(); data = client.DownloadString(requestString); } return data; }
/// <summary> /// Implementation! Connected to Quandl, request the data and then save to a file /// </summary> /// <param name="filename">The filename to save the output to</param> /// <param name="request">The request to make to Quandl</param> private static void RequestToFile(string filename, IQuandlRequest request) { QuandlConnection connection = new QuandlConnection(); var data = connection.Request(request); using (StreamWriter writer = new StreamWriter(filename)) { writer.Write(data); } }
private string Get(IQuandlRequest request) { string data = string.Empty; using (WebClient client = new WebClient()) { string requestString = request.ToRequestString(); data = client.DownloadString(requestString); } return(data); }
public string BuildURL(IQuandlRequest Request) { string NewURL = Request.GetURL(); if (NewURL.Contains("?") && NewURL.Contains("&")) { NewURL += "&api_key=" + mApiKey; } else { NewURL += "?api_key=" + mApiKey; } return(NewURL); }
public string Request(IQuandlRequest request) { string data = string.Empty; if (request is IQuandlRequest) { var requestGET = request as IQuandlRequest; data = Get(requestGET); } else if (request is IQuandlUploadRequest) { var requestPOST = request as IQuandlUploadRequest; data = Post(requestPOST); } else { throw new ArgumentException("The request supplied is not of a valid type", "request"); } return data; }
public string Request(IQuandlRequest request) { string data = string.Empty; if (request is IQuandlRequest) { var requestGET = request as IQuandlRequest; data = Get(requestGET); } else if (request is IQuandlUploadRequest) { var requestPOST = request as IQuandlUploadRequest; data = Post(requestPOST); } else { throw new ArgumentException("The request supplied is not of a valid type", "request"); } return(data); }
private string Get(IQuandlRequest request) { string data = string.Empty; using (WebClient client = new WebClient()) { string requestString = request.ToRequestString(); //try //{ data = client.DownloadString(requestString); //} /*catch (System.Net.WebException e) { if ((int)((HttpWebResponse)e.Response).StatusCode == 429) { Thread.Sleep(1000 * 60 * 10); data = client.DownloadString(requestString); } }*/ } return data; }
static string GetData(IQuandlRequest req, string sym, string dataset, FileFormats form, bool checkcache, bool compressedcache, DebugDelegate d) { if (_d == null) { _d = d; } try { var path = BarListImpl.GetDBLoc(PROGRAM, dataset + "_" + sym, 30, DateTime.Now, getformatext(form)); if (checkcache) { if (System.IO.File.Exists(path)) { try { var cached = Util.getfile(path, null); if (compressedcache) { var cacheddata = GZip.Uncompress(cached); v(sym + " " + dataset + " found " + cacheddata.Length.ToString("N0") + " bytes of cached data."); return(cacheddata); } } catch (Exception ex) { debug("Ignoring cache (will pull directly) after cache error for: " + dataset + " on " + sym + " err: " + ex.Message + ex.StackTrace); } } } var con = new QuandlConnection(); var data = con.Request(req); var isdataok = !qh.isQdlUnderMaintence(data); if (isdataok) { v(sym + " " + dataset + " retrieved " + data.Length.ToString("N0") + " bytes of " + dataset + " data."); // save it for later caching if (Util.setfile(path, compressedcache ? GZip.Compress(data) : data)) { v(sym + " " + dataset + " cached " + data.Length.ToString("N0") + " bytes of " + dataset + " data."); } else { v(sym + " " + dataset + " error caching " + data.Length.ToString("N0") + " bytes of " + dataset + " data. Will be re-pulled on next attempt."); } } else { debug(sym + " " + dataset + " can't be retrieved because quandl is down."); return(string.Empty); } return(data); } catch (Exception ex) { if (isVerboseDebugging) { debug("An error occurred getting data for: " + dataset + " on symbol: " + sym + " using url: " + req.ToRequestString()); debug("Error for " + dataset + " on symbol: " + sym + ": " + ex.Message + ex.StackTrace); } else { debug("An error occurred getting data for: " + dataset + " on symbol: " + sym + ", err: " + ex.Message + ex.StackTrace); } return(string.Empty); } }
static string GetData(IQuandlRequest req, string sym, string dataset, FileFormats form, bool checkcache, bool compressedcache, DebugDelegate d) { if (_d == null) _d = d; try { var path = BarListImpl.GetDBLoc(PROGRAM , dataset+"_"+sym, 30, DateTime.Now, getformatext(form)); if (checkcache) { if (System.IO.File.Exists(path)) { try { var cached = Util.getfile(path, null); if (compressedcache) { var cacheddata = GZip.Uncompress(cached); v(sym + " " + dataset + " found " + cacheddata.Length.ToString("N0") + " bytes of cached data."); return cacheddata; } } catch (Exception ex) { debug("Ignoring cache (will pull directly) after cache error for: " + dataset + " on " + sym + " err: " + ex.Message + ex.StackTrace); } } } var con = new QuandlConnection(); var data = con.Request(req); var isdataok = !qh.isQdlUnderMaintence(data) ; if (isdataok) { v(sym + " " + dataset + " retrieved " + data.Length.ToString("N0") + " bytes of " + dataset + " data."); // save it for later caching if (Util.setfile(path, compressedcache ? GZip.Compress(data) : data)) { v(sym + " " + dataset + " cached " + data.Length.ToString("N0") + " bytes of " + dataset + " data."); } else v(sym + " " + dataset + " error caching " + data.Length.ToString("N0") + " bytes of " + dataset + " data. Will be re-pulled on next attempt."); } else { debug(sym + " " + dataset + " can't be retrieved because quandl is down."); return string.Empty; } return data; } catch (Exception ex) { if (isVerboseDebugging) { debug("An error occurred getting data for: " + dataset + " on symbol: " + sym + " using url: " + req.ToRequestString()); debug("Error for " + dataset + " on symbol: " + sym + ": " + ex.Message + ex.StackTrace); } else debug("An error occurred getting data for: " + dataset + " on symbol: " + sym + ", err: " + ex.Message + ex.StackTrace); return string.Empty; } }