public override bool DownloadDailyData(string rootFolder, StockSerie stockSerie) { string url = @"http://www.gurufocus.com/ownership/%TICKER"; url = url.Replace("%TICKER", stockSerie.ShortName); ShortInterestSerie siSerie = StockDictionary.StockDictionarySingleton.ShortInterestDictionary[stockSerie.StockName]; siSerie.Initialise(); if (siSerie.Count > 0 && siSerie.Keys.Last() > (DateTime.Today.AddDays(15))) return false; if (File.GetLastWriteTime(Settings.Default.RootFolder + SHORTINTEREST_FOLDER + stockSerie.ShortName + "_SI.html").Date != DateTime.Today) { StockWebHelper swh = new StockWebHelper(); if (swh.DownloadFile(Settings.Default.RootFolder + SHORTINTEREST_FOLDER, stockSerie.ShortName + "_SI.html", url)) { string html = string.Empty; using ( StreamReader rw = new StreamReader(Settings.Default.RootFolder + SHORTINTEREST_FOLDER + stockSerie.ShortName + "_SI.html")) { html = rw.ReadToEnd(); html = html.Remove(0, html.IndexOf("<th>Short Interest</th>")); html = html.Remove(0, html.IndexOf("<tr><td>")); html = html.Remove(html.IndexOf("</tbody>")); html = html.Replace("</td></tr><tr><td>", Environment.NewLine); html = html.Replace("</td><td>", ";"); html = html.Replace("<tr><td>", ""); html = html.Replace("</td></tr>", ""); } using (Stream stringStream = new MemoryStream(Encoding.UTF8.GetBytes(html.Trim()))) { using (StreamReader rw = new StreamReader(stringStream)) { while (!rw.EndOfStream) { string[] fields = rw.ReadLine().Split(';'); ShortInterestValue siValue = new ShortInterestValue(DateTime.Parse(fields[0], usCulture), float.Parse(fields[1], usCulture), 0f, 0f); if (!siSerie.ContainsKey(siValue.Date)) { siSerie.Add(siValue.Date, siValue); } } } } siSerie.SaveToFile(); } } return false; }
public bool DownloadDailyData2(string rootFolder, StockSerie stockSerie) { string url = @"http://www.nasdaq.com/symbol/%TICKER/short-interest"; url = url.Replace("%TICKER", stockSerie.ShortName); ShortInterestSerie siSerie = StockDictionary.StockDictionarySingleton.ShortInterestDictionary[stockSerie.StockName]; siSerie.Initialise(); if (siSerie.Count > 0 && siSerie.Keys.Last() > (DateTime.Today.AddDays(15))) return false; StockWebHelper swh = new StockWebHelper(); if (swh.DownloadFile(Settings.Default.RootFolder + SHORTINTEREST_FOLDER, stockSerie.ShortName + "_SI.html", url)) { string html = string.Empty; using (StreamReader rw = new StreamReader(Settings.Default.RootFolder + SHORTINTEREST_FOLDER + stockSerie.ShortName + "_SI.html")) { html = rw.ReadToEnd(); html = html.Remove(0, html.IndexOf("Settlement Date")); html = html.Remove(0, html.IndexOf("<tr>")); html = html.Remove(html.IndexOf("</tbody>")); html = html.Replace("</tr>", ""); html = html.Replace("<tr>", ""); html = html.Replace("</td><td>", ";"); html = html.Replace("<td>", ""); html = html.Replace("</td>", ""); html = html.Replace("\t", ""); html = html.Replace("\r\n\r\n", "\r\n"); int index = html.IndexOf("<tr>"); } using (Stream stringStream = new MemoryStream(Encoding.UTF8.GetBytes(html))) { using (StreamReader rw = new StreamReader(stringStream)) { string line = rw.ReadLine(); while (!rw.EndOfStream) { string[] fields = rw.ReadLine().Split(';'); ShortInterestValue siValue = new ShortInterestValue(DateTime.Parse(fields[0], usCulture), float.Parse(fields[1], usCulture), float.Parse(fields[2], usCulture), float.Parse(fields[3], usCulture)); if (!siSerie.ContainsKey(siValue.Date)) { siSerie.Add(siValue.Date, siValue); } } } } siSerie.SaveToFile(); File.Delete(Settings.Default.RootFolder + SHORTINTEREST_FOLDER + stockSerie.ShortName + "_SI.html"); } return false; }