Exemple #1
0
 private void DoBackUrl()
 {
     if (!string.IsNullOrEmpty(Config.BackUrl))
     {
         var OpenList = GetOpenListFromBackUrl();
         if (OpenList.Count == 0)
         {
             return;                      //无抓取数据
         }
         var newestQiHao = OpenList.First().Term.ToString();
         var startQiNum  = Convert.ToInt32(LatestItem.Term.ToString().Substring(4)) + 1;
         var newestQiNum = Convert.ToInt32(newestQiHao.Substring(4));
         if (startQiNum > newestQiNum)
         {
             return;                           //无最新数据
         }
         //处理最新开奖数据
         var getQiHao = string.Empty;
         OpenCode5DTModel matchItem = null;
         for (var i = startQiNum; i <= newestQiNum; i++)
         {
             getQiHao  = i.ToString();
             matchItem = OpenList.Where(R => R.Term.ToString() == getQiHao).FirstOrDefault();
             if (matchItem != null && services.AddDTOpen5Code(currentLottery, matchItem))
             {
                 //Do Success Log
                 log.Info(GetType(), CommonHelper.GetJobBackLogInfo(Config, getQiHao));
                 LatestItem = matchItem;
                 isGetData  = true;
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        ///     通过主站点爬取开奖数据
        ///     (福建体彩网)
        /// </summary>
        private void DoTodayJobByMainUrl()
        {
            if (!string.IsNullOrEmpty(Config.MainUrl))
            {
                var openList = GetOpenListFromMainUrl(Config.MainUrl);
                if (openList.Count == 0)
                {
                    return;                      //无抓取数据
                }
                //抓取到的最新期数
                var newestQiHao = Convert.ToInt32(openList.Max(w => w.Term).ToString());
                //数据库里面最新期数
                var startQiNum = Convert.ToInt32(LatestItem.Term.ToString());
                if (startQiNum > newestQiHao)
                {
                    return;                           //无最新数据
                }
                //处理最新开奖数据
                var getQiHao = string.Empty;
                OpenCode5DTModel matchItem = null;
                for (var i = startQiNum; i <= newestQiHao; i++)
                {
                    getQiHao  = i.ToString();
                    matchItem = openList.FirstOrDefault(r => r.Term.ToString() == getQiHao);

                    if (matchItem != null && services.AddDTOpen5Code(currentLottery, matchItem))
                    {
                        //Do Success Log
                        log.Info(GetType(), CommonHelper.GetJobMainLogInfo(Config, getQiHao));
                        LatestItem = matchItem;
                        isGetData  = true;
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 执行昨天的数据插入
        /// </summary>
        private void DoYesterdayFailedListByBackUrl()
        {
            if (!string.IsNullOrEmpty(Config.BackUrl) && FailedQiHaoList.Count > 0)
            {
                var OpenList = GetOpenListFromBackUrl();
                if (OpenList.Count == 0)
                {
                    return;                      //无抓取数据
                }
                OpenCode5DTModel matchItem = null;
                var SuccessList            = new List <string>();
                foreach (var failedQiHao in FailedQiHaoList)
                {
                    matchItem = OpenList.Where(R => R.Term.ToString() == failedQiHao).FirstOrDefault();
                    if (matchItem != null && services.AddDTOpen5Code(currentLottery, matchItem))
                    {
                        //Do Success Log
                        log.Info(GetType(), CommonHelper.GetJobBackLogInfo(Config, failedQiHao));
                        if (matchItem.Term > LatestItem.Term)
                        {
                            LatestItem = matchItem;
                        }
                        SuccessList.Add(failedQiHao);
                        isGetData = true;
                    }
                }

                foreach (var successQiHao in SuccessList)
                {
                    FailedQiHaoList.Remove(successQiHao);
                }
            }
        }
Exemple #4
0
        /// <summary>
        ///     作业执行入口
        /// </summary>
        /// <param name="context">作业执行上下文</param>
        public void Execute(IJobExecutionContext context)
        {
            Config = CommonHelper.GetConfigFromDataMap(context.JobDetail.JobDataMap);
            //预设节假日不开奖
            GetOpenListFromMainUrl(Config.MainUrl);
            if (Config.SkipDate.Contains(CommonHelper.SCCSysDateTime.ToString("yyyyMMdd")))
            {
                return;
            }
            LatestItem = context.JobDetail.JobDataMap["LatestItem"] as OpenCode5DTModel;
            try
            {
                //服务启动时配置初始数据
                if (LatestItem == null)
                {
                    LatestItem = services.GetOpenCode5DTLastItem(currentLottery);
                    if (LatestItem == null)
                    {
                        LatestItem = new OpenCode5DTModel
                        {
                            Term     = CommonHelper.GenerateQiHaoYYYYQQQ(0),
                            OpenTime = new DateTime(CommonHelper.SCCSysDateTime.Year, 1, 1)
                        }
                    }
                    ;
                }

                //程序时间第二天,程序根据配置检查是否昨天有开奖
                isGetData = false;
                if (CommonHelper.CheckDTIsNeedGetData(Config))
                {
                    DoMainUrl();
                    DoBackUrl();
                }

                if (!LatestItem.Term.ToString().StartsWith(CommonHelper.SCCSysDateTime.ToString("yy")))
                {
                    LatestItem = new OpenCode5DTModel
                    {
                        Term     = CommonHelper.GenerateQiHaoYYYYQQQ(0),
                        OpenTime = new DateTime(CommonHelper.SCCSysDateTime.Year, 1, 1)
                    }
                }
                ;
                //当今日开奖并且当前时间是晚上8点过后开始抓取
                if (CommonHelper.CheckTodayIsOpenDay(Config) && CommonHelper.SCCSysDateTime.Hour > 12)
                {
                    DoMainUrl();
                    DoBackUrl();
                }
            }
            catch (Exception ex)
            {
                log.Error(GetType(), string.Format("【{0}】抓取时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            //保存最新期号
            context.JobDetail.JobDataMap["LatestItem"] = LatestItem;
        }
Exemple #5
0
        /// <summary>
        ///     获取备用站点开奖列表数据
        /// </summary>
        /// <param name="backUrl">备用站点</param>
        /// <returns></returns>
        private List <OpenCode5DTModel> GetOpenListFromBackUrl()
        {
            var result = new List <OpenCode5DTModel>();

            try
            {
                var htmlResource = NetHelper.GetUrlResponse(Config.BackUrl);
                if (htmlResource == null)
                {
                    return(result);
                }

                var doc = new HtmlDocument();
                doc.LoadHtml(htmlResource);
                var table = doc.DocumentNode.SelectSingleNode("//table");
                if (table == null)
                {
                    return(result);
                }
                var trs = table.ChildNodes.Where(node => node.Name == "tr").ToList();
                trs.RemoveAll(w => w.GetAttributeValue("class", "") != "");
                foreach (var item in trs)
                {
                    var tds = item.ChildNodes.Where(w => w.Name == "td").ToList();
                    ;
                    var qihao       = tds[0].InnerText.Trim();
                    var kaijianghao = tds[1].InnerText.Trim();
                    var opentime    = tds[9].InnerText.Trim();
                    var tmp         = new OpenCode5DTModel
                    {
                        Term     = long.Parse(qihao),
                        OpenTime = DateTime.Parse(opentime)
                    };
                    tmp.OpenCode1 = int.Parse(kaijianghao.Substring(0, 2));
                    tmp.OpenCode2 = int.Parse(kaijianghao.Substring(2, 2));
                    tmp.OpenCode3 = int.Parse(kaijianghao.Substring(4, 2));
                    tmp.OpenCode4 = int.Parse(kaijianghao.Substring(6, 2));
                    tmp.OpenCode5 = int.Parse(kaijianghao.Substring(8, 2));
                    OptimizeBackModel(ref tmp, item);
                    result.Add(tmp);
                }

                var checkDataHelper = new CheckDataHelper();
                var dbdata          = services.GetListS <OpenCode5DTModel>(currentLottery)
                                      .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
                checkDataHelper.CheckData(dbdata, result.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()),
                                          Config.Area, currentLottery);
                result = result.OrderByDescending(S => S.Term).ToList();
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过备用站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(result);
        }
Exemple #6
0
        /// <summary>
        ///     完善备用站点江苏体彩7位数开奖实体信息
        /// </summary>
        /// <param name="model"></param>
        private bool OptimizeBackModel(ref OpenCode5DTModel model, HtmlNode tr)
        {
            try
            {
                var entity = new KaijiangDetailsEntity();
                entity.KaiJiangItems = new List <Kaijiangitem>();
                var tds         = tr.ChildNodes.Where(w => w.Name == "td").ToList();
                var xiaoshoue   = tds[2].InnerText.Replace(",", "").Trim();
                var jiangchi    = "0";
                var tedengjiang = new Kaijiangitem
                {
                    Name       = "特等奖",
                    Total      = tds[3].InnerText.Trim(),
                    TotalMoney = tds[4].InnerText.Trim()
                };
                entity.KaiJiangItems.Add(tedengjiang);
                var yidengjiang = new Kaijiangitem
                {
                    Name       = "一等奖",
                    Total      = tds[5].InnerText.Trim(),
                    TotalMoney = tds[6].InnerText.Trim()
                };
                entity.KaiJiangItems.Add(yidengjiang);
                var erdengjiang = new Kaijiangitem
                {
                    Name       = "二等奖",
                    Total      = tds[7].InnerText.Trim(),
                    TotalMoney = tds[8].InnerText.Trim()
                };
                entity.KaiJiangItems.Add(erdengjiang);
                entity.Trje = xiaoshoue;
                entity.Gdje = jiangchi;
                model.Spare = entity.TryToJson();
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过备用站点优化开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(false);
        }
Exemple #7
0
        /// <summary>
        ///     副站数据爬取 地址:https://fx.cp2y.com/draw/history_10065_Y/
        /// </summary>
        /// <returns></returns>
        private List <OpenCode5DTModel> GetOpenListFromBackUrl()
        {
            var result = new List <OpenCode5DTModel>();

            try
            {
                var htmlResource = NetHelper.GetUrlResponse(Config.BackUrl, Encoding.GetEncoding("utf-8"));
                if (htmlResource == null)
                {
                    return(result);
                }

                var doc = new HtmlDocument();
                doc.LoadHtml(htmlResource);
                var table = doc.DocumentNode.SelectSingleNode("//table");
                if (table == null)
                {
                    return(result);
                }
                var              trs = table.ChildNodes.Where(node => node.Name == "tr").ToList();
                List <HtmlNode>  tds = null;
                string           term = string.Empty, openCodeString = string.Empty, optimizeUrl = string.Empty;
                OpenCode5DTModel model = null;
                for (var i = 0; i < trs.Count; i++)
                {
                    tds = trs[i].ChildNodes.Where(S => S.Name.ToLower() == "td").ToList();
                    if (tds.Count < 4)
                    {
                        continue;
                    }

                    model = new OpenCode5DTModel();
                    term  = tds[0].InnerText.Trim();
                    if (term.StartsWith((CommonHelper.SCCSysDateTime.Year - 1).ToString()))
                    {
                        break;
                    }

                    model.Term      = Convert.ToInt64(term);
                    openCodeString  = tds[2].InnerText.Replace("&nbsp;", "").Trim();
                    model.OpenCode1 = Convert.ToInt32(openCodeString.Substring(0, 2));
                    model.OpenCode2 = Convert.ToInt32(openCodeString.Substring(2, 2));
                    model.OpenCode3 = Convert.ToInt32(openCodeString.Substring(4, 2));
                    model.OpenCode4 = Convert.ToInt32(openCodeString.Substring(6, 2));
                    model.OpenCode5 = Convert.ToInt32(openCodeString.Substring(8, 2));
                    model.OpenTime  = Convert.ToDateTime(tds[1].InnerText.Trim());
                    //组装开奖详情
                    result.Add(model);
                }

                var checkDataHelper = new CheckDataHelper();
                var dbdata          = services.GetListS <OpenCode5DTModel>(currentLottery)
                                      .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
                checkDataHelper.CheckData(dbdata, result.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()),
                                          Config.Area, currentLottery);
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过副站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(result);
        }
Exemple #8
0
        private List <OpenCode5DTModel> GetOpenListFromMainUrl(string mainUrl)
        {
            var result = new List <OpenCode5DTModel>();

            try
            {
                var url          = new Uri(mainUrl);
                var htmlResource = NetHelper.GetUrlResponse(mainUrl, Encoding.GetEncoding("gb2312"));
                if (htmlResource == null)
                {
                    return(result);
                }

                var doc = new HtmlDocument();
                doc.LoadHtml(htmlResource);
                var table = doc.DocumentNode.SelectSingleNode("//table");
                if (table == null)
                {
                    return(result);
                }
                var trs = table.ChildNodes.Where(node => node.Name == "tr").ToList();
                OpenCode5DTModel model = null;
                HtmlNode         nodeA = null;
                var optimizeUrl        = string.Empty;
                for (var i = 2; i < trs.Count; i++) //第一二行为表头
                {
                    var trstyle = trs[i].Attributes["style"];
                    if (trstyle != null && trstyle.Value == "display:none")
                    {
                        continue;
                    }
                    var tds = trs[i].ChildNodes.Where(node => node.Name == "td").ToList();
                    if (tds.Count < 10)
                    {
                        continue;
                    }
                    model = new OpenCode5DTModel();
                    nodeA = tds[0].ChildNodes.Where(n => n.Name == "a").FirstOrDefault();
                    if (nodeA == null)
                    {
                        continue;
                    }
                    model.Term      = Convert.ToInt64(nodeA.InnerText.Trim());
                    optimizeUrl     = nodeA.Attributes["href"].Value;
                    model.DetailUrl = new Uri(url, optimizeUrl).AbsoluteUri;
                    model.OpenTime  = Convert.ToDateTime(tds[9].InnerText);
                    if (tds[1].ChildNodes.Count == 0)
                    {
                        continue;
                    }
                    var opencodeNode = tds[1].ChildNodes.Where(n => n.Name.ToLower() == "i").ToList();
                    if (opencodeNode.Count < 5)
                    {
                        continue;
                    }
                    model.OpenCode1 = Convert.ToInt32(opencodeNode[0].InnerText.Trim());
                    model.OpenCode2 = Convert.ToInt32(opencodeNode[1].InnerText.Trim());
                    model.OpenCode3 = Convert.ToInt32(opencodeNode[2].InnerText.Trim());
                    model.OpenCode4 = Convert.ToInt32(opencodeNode[3].InnerText.Trim());
                    model.OpenCode5 = Convert.ToInt32(opencodeNode[4].InnerText.Trim());
                    var details = GetKaijiangDetails(tds);
                    model.Spare = details;
                    result.Add(model);
                }

                var checkDataHelper = new CheckDataHelper();
                var dbdata          = services.GetListS <OpenCode5DTModel>(currentLottery)
                                      .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
                checkDataHelper.CheckData(dbdata, result.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()),
                                          Config.Area, currentLottery);
                result = result.OrderByDescending(S => S.Term).ToList();
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过主站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(result);
        }
Exemple #9
0
        /// <summary>
        ///     完善主站江苏体彩7位数开奖详情信息
        /// </summary>
        /// <param name="model"></param>
        private bool OptimizeMainModel(ref OpenCode5DTModel model)
        {
            var url = string.Format("http://www.jslottery.com/Lottery/LotteryDetails?PlayType=5&Issue={0}", model.Term);

            try
            {
                var entity = new KaijiangDetailsEntity();
                entity.KaiJiangItems = new List <Kaijiangitem>();

                var htmlResource = NetHelper.GetUrlResponse(url);


                if (!string.IsNullOrEmpty(htmlResource))
                {
                    var doc = new HtmlDocument();
                    doc.LoadHtml(htmlResource);
                    var tables = doc.DocumentNode.SelectNodes("//table");
                    if (tables.Count < 5)
                    {
                        return(false);
                    }
                    var trs = tables[4].ChildNodes[0].ChildNodes.Where(S => S.Name.ToLower() == "tr").ToList();
                    foreach (var tr in trs)
                    {
                        var tds = tr.ChildNodes.Where(S => S.Name.ToLower() == "td").ToList();
                        if (tds.Count < 3)
                        {
                            continue;
                        }
                        if (tds[0].InnerText == "特等奖")
                        {
                            var tmp = new Kaijiangitem
                            {
                                Name       = "特等奖",
                                Total      = tds[1].InnerText,
                                TotalMoney = tds[2].InnerText
                            };
                            entity.KaiJiangItems.Add(tmp);
                            // Level1Num = Convert.ToInt32(tds[1].InnerText);
                            // Level1Money = Convert.ToInt32(tds[2].InnerText);
                        }
                        else if (tds[0].InnerText == "一等奖")
                        {
                            var tmp = new Kaijiangitem
                            {
                                Name       = "一等奖",
                                Total      = tds[1].InnerText,
                                TotalMoney = tds[2].InnerText
                            };
                            entity.KaiJiangItems.Add(tmp);
                        }
                        else if (tds[0].InnerText == "二等奖")
                        {
                            var tmp = new Kaijiangitem
                            {
                                Name       = "二等奖",
                                Total      = tds[1].InnerText,
                                TotalMoney = tds[2].InnerText
                            };
                            entity.KaiJiangItems.Add(tmp);
                        }
                    }

                    var reg   = new Regex(@"本期投注总额<span>([\d.,]*?)</span>");
                    var match = reg.Match(htmlResource);
                    if (match.Success)
                    {
                        entity.Trje = (Convert.ToDecimal(match.Result("$1").Replace(",", string.Empty)) * 10000)
                                      .ToString();
                    }
                    else
                    {
                        reg   = new Regex(@"本期投注总额<span lang=""EN-US"">([\d.,]*?)</span>");
                        match = reg.Match(htmlResource);
                        if (match.Success)
                        {
                            entity.Trje = (Convert.ToDecimal(match.Result("$1").Replace(",", string.Empty)) * 10000)
                                          .ToString();
                        }
                    }

                    entity.Gdje = (Convert.ToDecimal(model.Spare.Replace(",", string.Empty)) * 10000).ToString();
                    model.Spare = entity.TryToJson();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过主站点完善抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(false);
        }
Exemple #10
0
        /// <summary>
        ///     获取主站开奖列表数据
        /// </summary>
        /// <param name="mainUrl">主站地址</param>
        /// <returns></returns>
        private List <OpenCode5DTModel> GetOpenListFromMainUrl(string mainUrl)
        {
            var result = new List <OpenCode5DTModel>();

            try
            {
                var postData     = "PlayType=5&currentPage=1&pageSize=200";
                var htmlResource = NetHelper.GetUrlResponse(mainUrl, "POST", postData, Encoding.UTF8);
                if (htmlResource == null)
                {
                    return(result);
                }


                var obj                       = htmlResource.JsonToEntity <JObject>();
                var lotteryList               = obj["LotteryNumberList"];
                OpenCode5DTModel model        = null;
                string[]         openCodeList = null;
                var issue                     = string.Empty;
                foreach (var item in lotteryList)
                {
                    issue = item["Issue"].ToString();
                    if (issue.StartsWith((CommonHelper.SCCSysDateTime.Year - 1).ToString()))
                    {
                        break;                                                                      //只抓取今年数据
                    }
                    model          = new OpenCode5DTModel();
                    model.Term     = Convert.ToInt64(issue);
                    model.OpenTime = Convert.ToDateTime(item["LotteryDate"].ToString());
                    openCodeList   = item["BasicNumber"].ToString().Trim().Replace("[", string.Empty)
                                     .Replace("]", string.Empty).Replace("\r\n", string.Empty).Replace("\"", string.Empty)
                                     .Split(',');
                    if (openCodeList.Length != 5)
                    {
                        continue;
                    }
                    model.OpenCode1 = Convert.ToInt32(openCodeList[0]);
                    model.OpenCode2 = Convert.ToInt32(openCodeList[1]);
                    model.OpenCode3 = Convert.ToInt32(openCodeList[2]);
                    model.OpenCode4 = Convert.ToInt32(openCodeList[3]);
                    model.OpenCode5 = Convert.ToInt32(openCodeList[4]);
                    model.Spare     = string.IsNullOrEmpty(item["PrizePool"].ToString().Replace("万元", string.Empty))
                        ? "0"
                        : item["PrizePool"].ToString().Replace("万元", string.Empty);
                    result.Add(model);
                }

                var checkDataHelper = new CheckDataHelper();
                var dbdata          = services.GetListS <OpenCode5DTModel>(currentLottery)
                                      .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
                checkDataHelper.CheckData(dbdata, result.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()),
                                          Config.Area, currentLottery);
                result = result.OrderByDescending(S => S.Term).ToList();
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过主站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(result);
        }
Exemple #11
0
        /// <summary>
        ///     爬取主网站信息
        /// </summary>
        /// <returns></returns>
        private List <OpenCode5DTModel> GetOpenListFromMainUrl(string mainUrl)
        {
            var result = new List <OpenCode5DTModel>();

            try
            {
                var htmlResource = NetHelper.GetUrlResponse(mainUrl, Encoding.GetEncoding("gb2312"));
                if (htmlResource == null)
                {
                    return(result);
                }
                var doc = new HtmlDocument();
                doc.LoadHtml(htmlResource);
                var table = doc.DocumentNode.SelectNodes("//table[@style='word-break:break-all']");
                if (table == null)
                {
                    return(result);
                }
                var trs = table[0].ChildNodes.Where(s => s.Name.ToLower() == "tr").ToList();

                List <HtmlNode>  tds = null;
                string           term = string.Empty, openCodeString = string.Empty, optimizeUrl = string.Empty;
                OpenCode5DTModel model = null;
                for (var i = 1; i < trs.Count; i++)
                {
                    tds = trs[i].ChildNodes.Where(S => S.Name.ToLower() == "td").ToList();
                    if (tds.Count < 8)
                    {
                        continue;
                    }

                    model = new OpenCode5DTModel();
                    term  = tds[0].InnerText.Trim();
                    if (term.StartsWith((CommonHelper.SCCSysDateTime.Year - 1).ToString()))
                    {
                        break;
                    }

                    model.Term      = Convert.ToInt64(term);
                    openCodeString  = tds[2].InnerText.Trim();
                    model.OpenCode1 = Convert.ToInt32(openCodeString.Substring(0, 2));
                    model.OpenCode2 = Convert.ToInt32(openCodeString.Substring(3, 2));
                    model.OpenCode3 = Convert.ToInt32(openCodeString.Substring(6, 2));
                    model.OpenCode4 = Convert.ToInt32(openCodeString.Substring(9, 2));
                    model.OpenCode5 = Convert.ToInt32(openCodeString.Substring(12, 2));
                    model.OpenTime  = Convert.ToDateTime(tds[1].InnerText.Trim());
                    //组装开奖详情
                    var details = GetKaijiangDetails(tds);
                    model.Spare = details;

                    model.DetailUrl = mainUrl;

                    result.Add(model);
                }

                var checkDataHelper = new CheckDataHelper();
                var dbdata          = services.GetListS <OpenCode5DTModel>(currentLottery)
                                      .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
                checkDataHelper.CheckData(dbdata, result.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()),
                                          Config.Area, currentLottery);
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过主站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(result);
        }
Exemple #12
0
        /// <summary>
        ///     完善备用站点江苏体彩7位数开奖实体信息
        /// </summary>
        /// <param name="model"></param>
        private bool OptimizeBackModel(ref OpenCode5DTModel model)
        {
            try
            {
                var entity = new KaijiangDetailsEntity();
                entity.KaiJiangItems = new List <Kaijiangitem>();
                var htmlResource = NetHelper.GetUrlResponse(model.DetailUrl, Encoding.GetEncoding("gb2312"));
                if (string.IsNullOrWhiteSpace(htmlResource))
                {
                    return(false);
                }
                var doc = new HtmlDocument();
                doc.LoadHtml(htmlResource);
                var table = doc.DocumentNode.SelectSingleNode("//table");
                if (table == null)
                {
                    return(false);
                }
                var             trs = table.ChildNodes.Where(N => N.Name.ToLower() == "tr").ToList();
                List <HtmlNode> tds = null;
                for (var i = 1; i < trs.Count; i++) //第一行为表头
                {
                    tds = trs[i].ChildNodes.Where(N => N.Name.ToLower() == "td").ToList();
                    if (tds.Count < 5)
                    {
                        continue;
                    }
                    if (tds[1].InnerText == "一等奖")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "一等奖",
                            Total      = tds[2].InnerText,
                            TotalMoney = tds[3].InnerText
                        };
                        entity.KaiJiangItems.Add(tmp);
                        //Level1Num = Convert.ToInt32(tds[2].InnerText);
                        // Level1Money = Convert.ToDecimal(tds[3].InnerText);
                    }

                    if (tds[1].InnerText == "二等奖")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "二等奖",
                            Total      = tds[2].InnerText,
                            TotalMoney = tds[3].InnerText
                        };
                        entity.KaiJiangItems.Add(tmp);
                    }

                    if (tds[1].InnerText == "三等奖")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "三等奖",
                            Total      = tds[2].InnerText,
                            TotalMoney = tds[3].InnerText
                        };
                        entity.KaiJiangItems.Add(tmp);
                    }

                    if (tds[1].InnerText == "好运二")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "好运二",
                            Total      = tds[2].InnerText,
                            TotalMoney = tds[3].InnerText
                        };
                        entity.KaiJiangItems.Add(tmp);
                    }

                    if (tds[1].InnerText == "好运三")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "好运三",
                            Total      = tds[2].InnerText,
                            TotalMoney = tds[3].InnerText
                        };
                        entity.KaiJiangItems.Add(tmp);
                    }

                    if (tds[1].InnerText == "好运四")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "好运四",
                            Total      = tds[2].InnerText,
                            TotalMoney = tds[3].InnerText
                        };
                        entity.KaiJiangItems.Add(tmp);
                    }
                }

                var reg   = new Regex(@"本期投注总额:([\d.,]*?)元");
                var match = reg.Match(htmlResource);
                if (match.Success)
                {
                    entity.Trje = match.Result("$1").Replace(",", string.Empty);
                }
                reg   = new Regex(@"奖池资金累计金额:([\d.,]*?)元");
                match = reg.Match(htmlResource);
                if (match.Success)
                {
                    entity.Gdje = match.Result("$1").Replace(",", string.Empty);
                }
                model.Spare = entity.TryToJson();
                //string.Format("{0},{1}^一等奖|{2}|{3},二等奖|{4}|{5},三等奖|{6}|{7},好运二|{8}|{9},好运三|{10}|{11},好运四|{12}|{13}",
                // Sales, Jackpot, Level1Num, Level1Money, Level2Num, Level2Money, Level3Num, Level3Money,
                //  Level4Num, Level4Money, Level5Num, Level5Money, Level6Num, Level6Money);
                return(true);
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过备用站点优化开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(false);
        }
Exemple #13
0
        /// <summary>
        ///     完善主站江苏体彩7位数开奖详情信息
        /// </summary>
        /// <param name="model"></param>
        private bool OptimizeMainModel(ref OpenCode5DTModel model)
        {
            try
            {
                var entity = new KaijiangDetailsEntity();
                entity.KaiJiangItems = new List <Kaijiangitem>();
                var htmlResource = NetHelper.GetUrlResponse(model.DetailUrl);
                if (string.IsNullOrWhiteSpace(htmlResource))
                {
                    return(false);
                }
                var doc = new HtmlDocument();
                doc.LoadHtml(htmlResource);
                var table = doc.DocumentNode.SelectSingleNode("//table");
                if (table == null)
                {
                    return(false);
                }
                var             trs = table.ChildNodes.Where(C => C.Name == "tr").ToList();
                List <HtmlNode> tds = null;
                foreach (var tr in trs)
                {
                    tds = tr.ChildNodes.Where(S => S.Name.ToLower() == "td").ToList();
                    if (tds.Count < 3)
                    {
                        continue;
                    }
                    if (tds[0].InnerText == "一等奖")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "一等奖",
                            Total      = tds[1].InnerText.Replace("注", ""),
                            TotalMoney = tds[2].InnerText.Replace("元", "")
                        };
                        entity.KaiJiangItems.Add(tmp);
                        // Level1Num = Convert.ToInt32(tds[1].InnerText.Replace("注", ""));
                        // Level1Money = Convert.ToInt32(tds[2].InnerText.Replace("元", ""));
                    }
                    else if (tds[0].InnerText == "二等奖")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "二等奖",
                            Total      = tds[1].InnerText.Replace("注", ""),
                            TotalMoney = tds[2].InnerText.Replace("元", "")
                        };
                        entity.KaiJiangItems.Add(tmp);
                    }
                    else if (tds[0].InnerText == "三等奖")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "三等奖",
                            Total      = tds[1].InnerText.Replace("注", ""),
                            TotalMoney = tds[2].InnerText.Replace("元", "")
                        };
                        entity.KaiJiangItems.Add(tmp);
                    }
                    else if (tds[0].InnerText == "好运二")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "好运二",
                            Total      = tds[1].InnerText.Replace("注", ""),
                            TotalMoney = tds[2].InnerText.Replace("元", "")
                        };
                        entity.KaiJiangItems.Add(tmp);
                    }
                    else if (tds[0].InnerText == "好运三")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "好运三",
                            Total      = tds[1].InnerText.Replace("注", ""),
                            TotalMoney = tds[2].InnerText.Replace("元", "")
                        };
                        entity.KaiJiangItems.Add(tmp);
                    }
                    else if (tds[0].InnerText == "好运四")
                    {
                        var tmp = new Kaijiangitem
                        {
                            Name       = "好运四",
                            Total      = tds[1].InnerText.Replace("注", ""),
                            TotalMoney = tds[2].InnerText.Replace("元", "")
                        };
                        entity.KaiJiangItems.Add(tmp);
                    }
                }

                var salesjackpot = model.Spare.Split('|');
                entity.Trje = salesjackpot[0];
                entity.Gdje = salesjackpot[1];
                model.Spare = entity.TryToJson();
                //string.Format("{0},{1}^一等奖|{2}|{3},二等奖|{4}|{5},三等奖|{6}|{7},好运二|{8}|{9},好运三|{10}|{11},好运四|{12}|{13}",
                // salesjackpot[0], salesjackpot[1], Level1Num, Level1Money, Level2Num, Level2Money, Level3Num, Level3Money,
                //  Level4Num, Level4Money, Level5Num, Level5Money, Level6Num, Level6Money);
                return(true);
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过主站点完善抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(false);
        }
Exemple #14
0
        /// <summary>
        ///     获取主站开奖列表数据
        /// </summary>
        /// <param name="mainUrl">主站地址</param>
        /// <returns></returns>
        private List <OpenCode5DTModel> GetOpenListFromMainUrl(string mainUrl)
        {
            var result = new List <OpenCode5DTModel>();

            try
            {
                var url          = new Uri(mainUrl);
                var htmlResource = NetHelper.GetUrlResponse(url.AbsoluteUri);
                if (htmlResource == null)
                {
                    return(result);
                }

                var doc = new HtmlDocument();
                doc.LoadHtml(htmlResource);
                var table = doc.DocumentNode.SelectSingleNode("//table");
                if (table == null)
                {
                    return(result);
                }
                var              trs = table.ChildNodes.Where(S => S.Name.ToLower() == "tr").ToList();
                List <HtmlNode>  tds = null;
                string           term = string.Empty, openCodeString = string.Empty, optimizeUrl = string.Empty;
                decimal          sales = 0, pool = 0;
                OpenCode5DTModel model = null;
                HtmlNode         nodeA = null;
                for (var i = 1; i == trs.Count; i++)
                {
                    tds = trs[i].ChildNodes.Where(S => S.Name.ToLower() == "td").ToList();
                    if (tds.Count < 8)
                    {
                        continue;
                    }
                    model = new OpenCode5DTModel();
                    term  = tds[0].InnerText.Trim();
                    if (term.StartsWith((CommonHelper.SCCSysDateTime.Year - 1).ToString()))
                    {
                        break;
                    }
                    model.Term      = Convert.ToInt64(tds[0].InnerText.Trim());
                    openCodeString  = tds[1].InnerText.Trim();
                    model.OpenCode1 = Convert.ToInt32(openCodeString.Substring(0, 2));
                    model.OpenCode2 = Convert.ToInt32(openCodeString.Substring(2, 2));
                    model.OpenCode3 = Convert.ToInt32(openCodeString.Substring(4, 2));
                    model.OpenCode4 = Convert.ToInt32(openCodeString.Substring(6, 2));
                    model.OpenCode5 = Convert.ToInt32(openCodeString.Substring(8, 2));
                    model.OpenTime  = Convert.ToDateTime(tds[6].InnerText.Trim());
                    sales           = Convert.ToDecimal(tds[2].InnerText.Trim());
                    pool            = Convert.ToDecimal(tds[5].InnerText.Trim());
                    model.Spare     = sales + "|" + pool;
                    nodeA           = tds[7].ChildNodes.Where(N => N.Name.ToLower() == "a").FirstOrDefault();
                    if (nodeA == null)
                    {
                        continue;
                    }
                    optimizeUrl     = nodeA.Attributes["href"].Value;
                    model.DetailUrl = new Uri(url, optimizeUrl).AbsoluteUri;
                    result.Add(model);
                }

                var checkDataHelper = new CheckDataHelper();
                var dbdata          = services.GetListS <OpenCode5DTModel>(currentLottery)
                                      .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
                checkDataHelper.CheckData(dbdata, result.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()),
                                          Config.Area, currentLottery);
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过主站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(result);
        }
Exemple #15
0
        private List <OpenCode5DTModel> GetOpenListFromBackUrl()
        {
            var result = new List <OpenCode5DTModel>();

            try
            {
                var url          = new Uri(Config.BackUrl);
                var htmlResource = NetHelper.GetUrlResponse(Config.BackUrl, Encoding.GetEncoding("utf-8"));
                if (htmlResource == null)
                {
                    return(result);
                }

                var doc = new HtmlDocument();
                doc.LoadHtml(htmlResource);
                var table = doc.DocumentNode.SelectNodes("//table[@id ='tabTrend']");
                if (table == null)
                {
                    return(result);
                }
                var trs = table[0].ChildNodes.Where(node => node.Name == "tr").ToList();
                OpenCode5DTModel model = null;
                var optimizeUrl        = string.Empty;
                for (var i = 1; i < trs.Count; i++) //第一二行为表头
                {
                    var tds = trs[i].ChildNodes.Where(node => node.Name == "td").ToList();
                    if (tds.Count < 10)
                    {
                        continue;
                    }

                    if (tds[1].ChildNodes.Count == 0)
                    {
                        continue;
                    }
                    var openCodeString = tds[1].InnerText.Trim();
                    if (openCodeString.Length != 6)
                    {
                        continue;
                    }
                    model           = new OpenCode5DTModel();
                    model.Term      = Convert.ToInt64(tds[0].InnerText.Trim());
                    model.OpenCode1 = Convert.ToInt32(openCodeString.Substring(0, 1));
                    model.OpenCode2 = Convert.ToInt32(openCodeString.Substring(1, 1));
                    model.OpenCode3 = Convert.ToInt32(openCodeString.Substring(2, 1));
                    model.OpenCode4 = Convert.ToInt32(openCodeString.Substring(3, 1));
                    model.OpenCode5 = Convert.ToInt32(openCodeString.Substring(5));
                    result.Add(model);
                }

                var checkDataHelper = new CheckDataHelper();
                var dbdata          = services.GetListS <OpenCode5DTModel>(currentLottery)
                                      .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr());
                checkDataHelper.CheckData(dbdata, result.ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()),
                                          Config.Area, currentLottery);
                result = result.OrderByDescending(S => S.Term).ToList();
            }
            catch (Exception ex)
            {
                log.Error(GetType(),
                          string.Format("【{0}】通过备用站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ex.Message));
            }

            return(result);
        }