private List <T_Yields> ConvertCrawlerModelToDbModel(StockYieldsViewModel crawlerDataList, string stock_id)
 {
     try
     {
         List <T_Yields> results = new List <T_Yields>();
         foreach (var item in crawlerDataList.Months)
         {
             results.Add(new T_Yields()
             {
                 Stock_ID   = stock_id,
                 YearMonth  = Convert.ToDateTime(item.YieldYear).ToString("yyyy/MM"),
                 MonthPrice = !string.IsNullOrWhiteSpace(item.MonthPrice) ? Convert.ToDouble(item.MonthPrice) : 0.0,
                 MonthRate  = !string.IsNullOrWhiteSpace(item.YieldRate) ? Convert.ToDouble(item.YieldRate) : 0.0,
             });
         }
         return(results);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #2
0
        public StockYieldsViewModel GetStockAllYields(string stock_id)
        {
            try
            {
                StockYieldsViewModel vm = new StockYieldsViewModel();
                var URL = this.stockYieldsURL(stock_id);

                var dom = BrowsingContext.New(config).OpenAsync(URL).Result;

                var mainSelector = @"#mainCol > div.br-trl > table > tbody ";

                var trCount = dom.QuerySelector(mainSelector)?.ChildElementCount;
                var flg     = 1;
                StockYieldsSelector selector = new StockYieldsSelector();

                for (int tr = 0; tr < trCount; tr++)
                {
                    selector.Months.Add(new Yield());
                    vm.Months.Add(new Yield());

                    selector.Months[tr].YieldYear  = mainSelector + $"> tr:nth-child({tr + flg}) > td:nth-child(1)";
                    selector.Months[tr].YieldRate  = mainSelector + $"> tr:nth-child({tr + flg}) > td:nth-child(2)";
                    selector.Months[tr].MonthPrice = mainSelector + $"> tr:nth-child({tr + flg}) > td:nth-child(3)";
                }

                for (int i = 0; i < vm.Months.Count; i++)
                {
                    ReflectionViewModel(dom, selector.Months[i], vm.Months[i]);
                }
                return(vm);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }