Example #1
0
        /*public void Download_PerDay(DateTime date)
         * {
         *  dynamic[] equility_pages = new dynamic[] { new PageStock(), new PageForeign() };//, new PageJuristic("selfoper_"), new PageJuristic("investtrust_"), };
         *
         *  foreach (dynamic page in equility_pages)
         *  {
         *      current_download_status = "Downloading " + page.getFilePrefix() + date.ToShortDateString();
         *      Logger.Log(current_download_status);
         *      page.download_page(page.getPageUrl(date),   date);
         *      Thread.Sleep(5000);
         *  }
         * }*/

        public void BatchDownloadStockTrading()
        {
            dynamic[] equility_pages = new dynamic[] { new PageStock(), new PageForeign() };

            //DateTime date = checkDownload ? StartDate : equility_pages[0].getLastDBDate(sql_db, "2379");
            DateTime date = DbSql.getLastDBDate("2379");

            date = date.CompareTo(StartDate) > 0 ? date : StartDate;

            while (!date.Equals(DateTime.Today))
            {
                date = date.AddDays(1);
                //Logger.v("Downloading data starting from " + String.Format("{0}", date));
                if (!TradingDays.IsTradingDay(date))
                {
                    continue;
                }
                //Download_PerDay(date);
                foreach (dynamic page in equility_pages)
                {
                    String content = String.Empty;
                    if (!File.Exists(TargetDirectory + page.getFileName(date)))
                    {
                        current_download_status = "Downloading " + page.getFilePrefix() + date.ToShortDateString();
                        Logger.Log(current_download_status);
                        content = page.download_page(page.getPageUrl(date), Encoding.GetEncoding("utf-8"));
                        Thread.Sleep(5000);
                        using (StreamWriter sw = new StreamWriter(TargetDirectory + page.getFileName(date), false, Encoding.GetEncoding("utf-8")))
                        {
                            sw.Write(content);
                            sw.Close();
                        }
                    }
                    else
                    {
                        using (StreamReader sr = new StreamReader(TargetDirectory + page.getFileName(date), Encoding.GetEncoding("utf-8")))
                        {
                            content = sr.ReadToEnd();
                        }
                    }
                    ArrayList stock_data = page.ParseHtml(content, date);
                    if (stock_data.Count > 0)
                    {
                        page.DBSave(stock_data);
                    }
                }
                //Thread.Sleep(5000);
            }
        }