Пример #1
0
        /// <summary>
        /// 获取THS龙虎榜数据
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        public List <object> GetLHB(string stockCode, string source = "THS")
        {
            var resList = new List <object>();

            if ("THS" == source.ToUpper() && !string.IsNullOrWhiteSpace(stockCode)) //
            {
                var lhbHtml = DataSourceTHS.CreateInstance().GetGGLHB(stockCode);
                if (string.IsNullOrWhiteSpace(lhbHtml))
                {
                    lhbHtml = WebDataSource.GetDataFromHttpAgent(string.Format("http://aifuwu.wang/API.ashx?c=WangJun.Stock.DataSourceTHS&m=GetGGLHB&p={0}", stockCode));
                }

                var lhbDict = NodeService.Get(CONST.NodeServiceUrl, "同花顺", "GetDataFromHtml", new { ContentType = "THS个股龙虎榜", Page = lhbHtml });
                resList.Add((lhbDict as Dictionary <string, object>)["PageData"]);
                ThreadManager.Pause(seconds: 2);
                var lhbmxUrlList = DataSourceTHS.CreateInstance().GetUrlGGLHBMX(lhbHtml);
                foreach (var lhbMXUrl in lhbmxUrlList)
                {
                    var lhbMXHtml = DataSourceTHS.CreateInstance().GetGGLHBMX(stockCode, lhbMXUrl);
                    if (string.IsNullOrWhiteSpace(lhbMXHtml))
                    {
                        //lhbHtml = WebDataSource.GetDataFromHttpAgent(string.Format("http://aifuwu.wang/API.ashx?c=WangJun.Stock.DataSourceTHS&m=GetGGLHBMX&p={0}", stockCode));
                    }
                    var lhbMXDict = NodeService.Get(CONST.NodeServiceUrl, "同花顺", "GetDataFromHtml", new { ContentType = "THS个股龙虎榜明细", Page = lhbMXHtml });
                    resList.Add((lhbMXDict as Dictionary <string, object>)["PageData"]);
                    ThreadManager.Pause(seconds: 1);
                }
            }

            return(resList);
        }
        /// <summary>
        /// 更新个股首页概览页面
        /// </summary>
        /// <param name="stockCode"></param>
        public void UpdateZJLX(string stockCode, string stockName)
        {
            var webSource = DataSourceTHS.CreateInstance();
            var db        = DataStorage.GetInstance();
            var html      = webSource.GetJZLX(stockCode);

            var jsonFilter = string.Format("{{\"StockCode\":\"{0}\",\"ContentType\":\"资金流向\"}}", stockCode);
            var list       = db.Find("PageSource", "PageStock", jsonFilter);

            if (1 == list.Count) ///若已经存储
            {
                list[0]["UpdateTime"] = DateTime.Now;
                list[0]["Page"]       = html;
                list[0]["MD5"]        = Convertor.Encode_MD5(html);
                db.Save(list[0], "PageStock", "PageSource");
            }
            else if (0 == list.Count) ///若没有存储
            {
                var item = new
                {
                    StockCode   = stockCode,
                    StockName   = stockName,
                    ContentType = "资金流向",
                    Url         = string.Format("http://stockpage.10jqka.com.cn/{0}/", stockCode),
                    CreateTime  = DateTime.Now,
                    Page        = html,
                    MD5         = Convertor.Encode_MD5(html),
                };
                db.Save(item, "PageStock", "PageSource");
            }
        }
        /// <summary>
        /// 更新页面
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="stockName"></param>
        /// <param name="contentType"></param>
        /// <param name="url"></param>
        /// <param name="date"></param>
        /// <param name="rid"></param>
        public void UpdatePage(string stockCode, string stockName, string contentType, string url, string date = null, string rid = null)
        {
            var webSource = DataSourceTHS.CreateInstance();
            var db        = DataStorage.GetInstance();
            var html      = webSource.GetPage(contentType, stockCode, date, rid);///获取页面

            var jsonFilter = string.Format("{{\"StockCode\":\"{0}\",\"ContentType\":\"{1}\"}}", stockCode, contentType);
            var list       = db.Find("PageSource", "PageStock", jsonFilter);

            if (1 == list.Count) ///若已经存储
            {
                list[0]["UpdateTime"] = DateTime.Now;
                list[0]["Page"]       = html;
                list[0]["MD5"]        = Convertor.Encode_MD5(html);
                db.Save(list[0], "PageStock", "PageSource");
            }
            else if (0 == list.Count) ///若没有存储
            {
                var item = new
                {
                    StockCode   = stockCode,
                    StockName   = stockName,
                    ContentType = contentType,
                    Url         = url,
                    CreateTime  = DateTime.Now,
                    Page        = html,
                    MD5         = Convertor.Encode_MD5(html),
                };
                db.Save(item, "PageStock", "PageSource");
            }
        }
Пример #4
0
        /// <summary>
        /// 更新页面
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="stockName"></param>
        /// <param name="contentType"></param>
        /// <param name="url"></param>
        /// <param name="date"></param>
        /// <param name="rid"></param>
        public void UpdatePage(string stockCode, string stockName, string contentType, string url = null, Dictionary <string, object> exData = null)
        {
            var webSource    = DataSourceTHS.CreateInstance();
            var db           = DataStorage.GetInstance("170");
            var html         = webSource.GetPage(contentType, stockCode, url, exData);///获取页面
            var subLinkArray = new List <string>();

            var jsonFilter = string.Format("{{\"StockCode\":\"{0}\",\"ContentType\":\"{1}\"}}", stockCode, contentType);

            if ("个股龙虎榜" == contentType)
            {
                subLinkArray = webSource.GetUrlGGLHBMX(html); ///个股龙虎榜明细链接
                foreach (var subUrl in subLinkArray)
                {
                    this.UpdatePage(stockCode, stockName, "个股龙虎榜明细", subUrl);
                }
            }
            else if ("个股龙虎榜明细" == contentType)
            {
                jsonFilter = string.Format("{{\"StockCode\":\"{0}\",\"ContentType\":\"{1}\",\"Url\":\"{2}\"}}", stockCode, contentType, url);
            }
            else if ("SINA个股历史交易" == contentType)
            {
                var year = exData["Year"];
                var jidu = exData["JiDu"];
                jsonFilter = string.Format("{{\"StockCode\":\"{0}\",\"ContentType\":\"{1}\",\"Year\":\"{2}\",\"JiDu\":\"{3}\"}}", stockCode, contentType, year, jidu);
            }
            else if ("SINA个股历史交易明细" == contentType)
            {
                //var year = exData["Year"];
                //var jidu = exData["JiDu"];
                //jsonFilter = string.Format("{{\"StockCode\":\"{0}\",\"ContentType\":\"{1}\",\"Year\":\"{2}\",\"JiDu\":\"{3}\"}}", stockCode, contentType, year, jidu);
            }

            var list = db.Find("PageSource", "PageStock", jsonFilter);

            if (1 == list.Count) ///若已经存储
            {
                list[0]["UpdateTime"] = DateTime.Now;
                list[0]["Page"]       = html;
                list[0]["MD5"]        = Convertor.Encode_MD5(html);
                db.Save(list[0], "PageStock", "PageSource");
            }
            else if (0 == list.Count) ///若没有存储
            {
                var item = new
                {
                    StockCode   = stockCode,
                    StockName   = stockName,
                    ContentType = contentType,
                    Url         = url,
                    CreateTime  = DateTime.Now,
                    Page        = html,
                    MD5         = Convertor.Encode_MD5(html),
                    LinkArray   = subLinkArray
                };
                db.Save(item, "PageStock", "PageSource");
            }
        }
Пример #5
0
        public Dictionary <string, string> GetAllStockCode(string source = "THS")
        {
            var res = new Dictionary <string, string>();

            if ("THS" == source.ToUpper())
            {
                res = DataSourceTHS.CreateInstance().GetAllStockCode();
            }

            return(res);
        }
Пример #6
0
        /// <summary>
        /// 获取THS资金流向
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        public object GetZJLX(string stockCode, string source = "THS")
        {
            var res = new object();

            if ("THS" == source.ToUpper() && !string.IsNullOrWhiteSpace(stockCode)) //
            {
                var html = DataSourceTHS.CreateInstance().GetJZLX(stockCode);
                if (string.IsNullOrWhiteSpace(html))
                {
                    html = WebDataSource.GetDataFromHttpAgent(string.Format("http://aifuwu.wang/API.ashx?c=WangJun.Stock.DataSourceTHS&m=GetZJLX&p={0}", stockCode));
                }

                var resDict = NodeService.Get(CONST.NodeServiceUrl, "同花顺", "GetDataFromHtml", new { ContentType = "THS资金流向", Page = html });
                return(resDict);
            }

            return(res);
        }
        /// <summary>
        /// 更新股票代码信息
        /// </summary>
        public void UpdateAllStockCode(string dataSourceName = "THS")
        {
            var db         = DataStorage.GetInstance();
            var dataSource = new Dictionary <string, string>();

            db.Delete("{\"ContentType\":\"股票代码\"}", "BaseInfo", "StockTask");
            if ("THS".ToUpper() == dataSourceName.ToUpper())
            {
                dataSource = DataSourceTHS.CreateInstance().GetAllStockCode();
            }

            foreach (var srcItem in dataSource)
            {
                var item = new { ContentType = "股票代码", StockCode = srcItem.Key, StockName = srcItem.Value, CreateTime = DateTime.Now };

                db.Save(item, "BaseInfo", "StockTask");
            }
        }
Пример #8
0
        /// <summary>
        /// 获取指定日期的新闻
        /// </summary>
        public void GetNewsListCJYW(string dateTime)
        {
            if (StringChecker.IsDateTime(dateTime))
            {
                var formatDate     = string.Format("{0:yyyyMMdd}", Convert.ToDateTime(dateTime));
                var mongo          = DataStorage.GetInstance(DBType.MongoDB);
                var webSrc         = DataSourceTHS.CreateInstance();
                var newNewsList    = new Dictionary <string, object>();
                var listHtml       = webSrc.GetNewsListCJYW(Convert.ToDateTime(dateTime));
                var dbName         = CONST.DB.DBName_StockService;
                var collectionNews = CONST.DB.CollectionName_News;

                if (!string.IsNullOrWhiteSpace(listHtml))
                {
                    var resDict = NodeService.Get(CONST.NodeServiceUrl, "同花顺", "GetDataFromHtml", new { ContentType = "THS财经要闻新闻列表", Page = listHtml }) as Dictionary <string, object>;
                    var resList = resDict["PageData"] as ArrayList;
                    if (null != resList)
                    {
                        foreach (Dictionary <string, object> listItem in resList)
                        {
                            var href      = listItem["Href"].ToString().Trim();
                            var parentUrl = string.Format("http://news.10jqka.com.cn/today_list/{0}/", formatDate).Trim();
                            var newsHtml  = webSrc.GetNewsArticle(href, parentUrl);
                            if (!string.IsNullOrWhiteSpace(newsHtml))
                            {
                                TaskStatusManager.Set("GetNewsListCJYW", new { ID = "GetNewsListCJYW", CreateTime = DateTime.Now, Status = "准备操作THS财经要闻新闻详细", Html = newsHtml });
                                var resItem   = NodeService.Get(CONST.NodeServiceUrl, "同花顺", "GetDataFromHtml", new { ContentType = "THS财经要闻新闻详细", Page = newsHtml }) as Dictionary <string, object>;
                                var resDetail = resItem["PageData"] as Dictionary <string, object>;
                                if (null != resDetail)
                                {
                                    var newsCreateTimeString = resDetail["CreateTime"].ToString().Trim();
                                    var svItem = new
                                    {
                                        ContentType    = "THS财经要闻",
                                        Title          = resDetail["Title"].ToString().Trim(),
                                        Url            = href,
                                        ParentUrl      = parentUrl,
                                        SourceHref     = resDetail["SourceHref"].ToString().Trim(),
                                        SourceName     = resDetail["SourceName"].ToString().Trim(),
                                        NewsCreateTime = (StringChecker.IsDateTime(newsCreateTimeString))?Convert.ToDateTime(newsCreateTimeString):DateTime.MinValue,
                                        Content        = resDetail["Content"].ToString().Trim(),
                                        Tag            = Convert.ToInt32(formatDate),
                                        CreateTime     = DateTime.Now,
                                        PageMD5        = "无"
                                    };
                                    newNewsList.Add(href, svItem);
                                    LOGGER.Log(string.Format("获取一个新闻正文 {0}", svItem.Title));
                                    ThreadManager.Pause(seconds: 5); ///5秒钟更新一次新闻


                                    ///分词
                                    var task = Task.Factory.StartNew(() =>
                                    {
                                        var fcZStartTime = DateTime.Now;
                                        this.SaveFenCi(svItem.Content, svItem.Url);
                                        LOGGER.Log(string.Format("分词花费时间 开始时间:{0} 花费时间:{1}", fcZStartTime, DateTime.Now - fcZStartTime));
                                    });
                                }
                            }
                        }

                        foreach (var svItem in newNewsList)
                        {
                            var filter = "{\"Url\":\"" + svItem.Key + "\"}";
                            mongo.Save3(dbName, collectionNews, svItem.Value, filter);
                        }
                    }
                }
                else
                {
                    LOGGER.Log(string.Format("获取的新闻列表为空白"));
                }
            }
            else
            {
                LOGGER.Log(string.Format("传入的时间字符串不对:{0}", dateTime));
                ThreadManager.Pause(minutes: 5);
            }
        }