示例#1
0
文件: JL11X5Job.cs 项目: PenAndy/SCC
        /// <summary>
        ///     从备用站抓取开奖数据 昨天/今天
        /// </summary>
        /// <param name="IsToday"></param>
        /// <returns></returns>
        /// <summary>
        ///     从主站抓取开奖数据 昨天/今天
        /// </summary>
        /// <param name="IsToday"></param>
        /// <returns></returns>
        private List <JL11X5Entity> GetDocByMainUrl(bool IsToday = true)
        {
            var list = new List <JL11X5Entity>();

            try
            {
                var time = DateTime.Now;
                var arg  = new OpenCaiApiArg
                {
                    code = EnumHelper.GetLotteryCode(SCCLottery.JiLin11X5),
                    // rows = int.Parse(GetPeriodsNumberToDay(time, IsToday)),
                    date = time.ToString("yyyy-MM-dd")
                };
                if (!IsToday)
                {
                    arg.date = time.AddDays(-1).ToString("yyyy-MM-dd");
                }
                var data = OpenCaiApiServices.GetOpenCaiApiData(arg);
                if (data == null)
                {
                    return(list);
                }

                if (data.data != null)
                {
                    if (data.data.Count == 0)
                    {
                        return(list);
                    }

                    for (var i = 0; i < data.data.Count; i++)
                    {
                        var tmp = new JL11X5Entity
                        {
                            QiHao       = data.data[i].GetTermStr(),
                            KaiJiangHao = data.data[i].GetOpenCodeStr(),
                            OpenTime    = DateTime.Parse(data.data[i].opentime)
                        };
                        list.Add(tmp);
                    }

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

            return(list);
        }
示例#2
0
文件: JL11X5Job.cs 项目: PenAndy/SCC
        /// 将此彩种指定期号和开奖号码保存至数据库
        /// </summary>
        /// <param name="QiHao">期号</param>
        /// <param name="OpenCode">开奖号码(形如01,02,03)</param>
        /// <param name="IsYesterdayRecord">是否是保存昨天的记录</param>
        /// <returns></returns>
        private bool SaveRecord(JL11X5Entity data)
        {
            var model = new OpenCode5Model();

            model.Term = Convert.ToInt64(data.QiHao); //期号
            var haoMaArray = data.KaiJiangHao.Split(',');

            model.OpenCode1 = Convert.ToInt32(haoMaArray[0]);
            model.OpenCode2 = Convert.ToInt32(haoMaArray[1]);
            model.OpenCode3 = Convert.ToInt32(haoMaArray[2]);
            model.OpenCode4 = Convert.ToInt32(haoMaArray[3]);
            model.OpenCode5 = Convert.ToInt32(haoMaArray[4]);
            model.OpenTime  = data.OpenTime;
            if (services.AddOpen5Code(currentLottery, model))
            {
                GetMaxPeriodNum((int)model.Term);  //添加成功存放期数
                return(true);
            }

            return(false);
        }
示例#3
0
文件: JL11X5Job.cs 项目: PenAndy/SCC
        /// <summary>
        ///     从备用站抓取开奖数据 昨天/今天
        /// </summary>
        /// <param name="IsToday"></param>
        /// <returns></returns>

        #region   爬取爱彩乐网站数据
        private List <JL11X5Entity> GetDocByBackUrl(bool IsToday = true)
        {
            var list = new List <JL11X5Entity>();

            try
            {
                var day = "?op=dcjb&num=jt";
                if (!IsToday)
                {
                    day = "?op=dcjb&num=zt";
                }
                var url          = string.Format("{0}{1}", Config.BackUrl, day);
                var HtmlResource = NetHelper.GetUrlResponse(url);
                if (!string.IsNullOrWhiteSpace(HtmlResource))
                {
                    var doc = new HtmlDocument();
                    doc.LoadHtml(HtmlResource);
                    var tables       = doc.DocumentNode.SelectNodes("//table");
                    var tbody        = tables[0].ChildNodes.Where(node => node.Name == "tbody").ToList();
                    var matchQiHao   = string.Empty;
                    var matchKJHaoMa = string.Empty;
                    foreach (var item in tables[1].ChildNodes)
                    {
                        if (item.HasChildNodes && item.Name == "tr")
                        {
                            var opencode = new List <string>();
                            var num      = string.Empty;
                            foreach (var item2 in item.ChildNodes)
                            {
                                if (item2.GetAttributeValue("class", "") == "chart-bg-qh")
                                {
                                    num = item2.InnerText.Trim();
                                }
                                if (item2.GetAttributeValue("class", "") == "cc")
                                {
                                    //数据加密保存在此,去掉两头然后base64转码
                                    var base64str = item2.InnerText.Trim().Substring(1);
                                    base64str = base64str.Substring(0, base64str.Length - 1);
                                    var codestr = DecodeBase64(Encoding.Default, base64str);
                                    opencode.Add(codestr);
                                }
                            }

                            if (opencode.Count == 5)
                            {
                                var qihao = num;
                                var tmp   = new JL11X5Entity
                                {
                                    QiHao       = num,
                                    KaiJiangHao = CommonHelper.TRHandleCode(string.Join(",", opencode)),
                                    OpenTime    = GetOpenTimeByPeriodNum(int.Parse(num))
                                };
                                list.Add(tmp);
                            }
                        }
                    }
                }

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

            return(list);
        }