示例#1
0
文件: IhBF.cs 项目: chanhan/ap_follow
        public IhBF(DateTime today)
            : base(ESport.Hockey_IHBF)
        {
            if (string.IsNullOrWhiteSpace(this.sWebUrl))
            {
                this.sWebUrl = "http://d.flashscore.com/x/feed/f_4_0_8_asia_1";
            }
            if (string.IsNullOrWhiteSpace(this.sWebUrl1))
            {
                this.sWebUrl1 = "http://d.flashscore.com/x/feed/proxy";
            }
            if (string.IsNullOrWhiteSpace(this.sWebUrl2))
            {
                this.sWebUrl2 = "http://d.flashscore.com/x/feed/f_4_-1_8_asia_1";
            }
            if (string.IsNullOrWhiteSpace(this.sWebUrl3))
            {
                this.sWebUrl3 = "http://d.flashscore.com/x/feed/f_4_";
            }
            this.Logs = new LogFile(ESport.Hockey_IHBF);//設定log type
            // 設定
            this.AllianceID = 0;
            this.GameType = "IHBF";
            this.GameDate = GetUtcTw(today).Date; // 只取日期
            this.DownHome = new IHDownload(this.Sport, this.GameDate, sWebUrl, "f_4_0_8_asia_1");
            this.DownHomeHeader = new Dictionary<string, string>();
            this.DownHomeHeader["Accept"] = "*/*";
            this.DownHomeHeader["Accept-Charset"] = "utf-8;q=0.7,*;q=0.3";
            this.DownHomeHeader["Accept-Encoding"] = "gzip,deflate,sdch";
            this.DownHomeHeader["Accept-Language"] = "*";
            this.DownHomeHeader["X-Fsign"] = "SW9D1eZo";
            this.DownHomeHeader["X-GeoIP"] = "1";
            this.DownHomeHeader["X-utime"] = "1";
            this.DownHomeHeader["Cookie"] = "__utma=175935605.237435887.1433729535.1433729535.1433732345.2; __utmb=175935605.2.10.1433732345; __utmc=175935605; __utmz=175935605.1433732345.2.2.utmcsr=flashscore.com|utmccn=(referral)|utmcmd=referral|utmcct=/tennis/; __utmt=1; __gads=ID=95d4003915b743c6:T=1433729537:S=ALNI_MYpkSaA3-m9gggcZp-An3QTk6uUOg";
            this.DownHomeHeader["Host"] = "d.flashscore.com";
            this.DownHomeHeader["Referer"] = this.sWebUrl1;
            // 昨天
            this.DownReal = new List<IHDownload>();
            this.DownReal.Add(new IHDownload(this.Sport, this.GameDate.AddDays(startIndex), this.sWebUrl2, "f_4_-1_8_asia_1"));
            // 往後 7 天
            for (int i = 1; i <= endIndex; i++)
            {
                this.DownReal.Add(new IHDownload(this.Sport, this.GameDate.AddDays(i), sWebUrl3 + i + "_8_asia_1", "f_4_" + i + "_8_asia_1"));
            }
            // 讀取隊伍表/聯盟表
            this.LoadTeamAndAlliance();

            #region 從資料庫中取得舊資料

            GetOldGames();

            #endregion 從資料庫中取得舊資料
        }
示例#2
0
文件: IhBF.cs 项目: chanhan/ap_follow
        /// <summary>
        /// 取得資料。(Asiascore)
        /// </summary>
        /// <param name="data">資料</param>
        /// <param name="playMinute">比賽的時間長度</param>
        protected Dictionary<string, BasicInfo> GetDataByAsiaScore(IHDownload download, int playMinute)
        {
            string html = download.Data;
            // 沒有資料就離開
            if (string.IsNullOrEmpty(html))
                return null;
            Dictionary<string, BasicInfo> result = new Dictionary<string, BasicInfo>();
            BasicInfo gameInfo = null;
            // 判斷資料
            string[] all = html.Split(new string[] { "¬~ZA÷" }, StringSplitOptions.RemoveEmptyEntries);

            // 聯盟 (第一筆是多餘的)
            int orderBy = 1;
            for (int allianceIndex = 1; allianceIndex < all.Length; allianceIndex++)
            {
                // 比賽集合
                string[] games = ("ZA÷" + all[allianceIndex]).Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
                string allianceName = null;
                string trackerText = null;
                // 聯盟資料
                // 比賽資料
                for (int gameIndex = 0; gameIndex < games.Length; gameIndex++)
                {
                    Dictionary<string, string> info = new Dictionary<string, string>();

                    #region 取出資料
                    string[] data = games[gameIndex].Split(new string[] { "¬" }, StringSplitOptions.RemoveEmptyEntries);
                    // 資料
                    foreach (string d in data)
                    {
                        string[] txt = d.Split(new string[] { "÷" }, StringSplitOptions.RemoveEmptyEntries);
                        // 記錄
                        info[txt[0]] = txt[1];
                    }
                    #endregion
                    #region 第一筆是聯盟
                    if (gameIndex == 0)
                    {
                        allianceName = info["ZA"];
                        if (info["ZF"] == "2")
                        {
                            trackerText = "只顯示最終比分";
                        }
                        continue;
                    }
                    else
                    {
                        // 沒有編號就往下處理
                        if (!info.ContainsKey("AA"))
                            continue;
                    }
                    #endregion

                    // 沒有隊伍就往下處理
                    if (!info.ContainsKey("AE") || !info.ContainsKey("AF"))
                        continue;

                    // 時間是 1970 年加上 Ti
                    DateTime gameTime = DateTime.Parse("1970/1/1 00:00:00").AddTicks(long.Parse(info["AD"]) * 10000000);
                    // 轉成台灣時間 UTC+8
                    gameTime = gameTime.AddHours(8);

                    // 建立比賽資料
                    gameInfo = null;
                    gameInfo = new BasicInfo(this.AllianceID, this.GameType, gameTime, info["AA"]);
                    gameInfo.OverDayGame = false;
                    gameInfo.Home = info["AE"].Replace("GOAL", "").Replace("'", "''");
                    gameInfo.Away = info["AF"].Replace("GOAL", "").Replace("'", "''");
                    // 2014/04/18, 新增聯盟(含賽別)
                    gameInfo.AllianceName = allianceName.Replace("'", "''");
                    gameInfo.AwayPoint = "0";
                    gameInfo.HomePoint = "0";
                    gameInfo.TrackerText = "";
                    #region 分數
                    if (info.ContainsKey("AG"))
                    {
                        string[] nums = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };
                        for (int i = 0; i < nums.Length; i += 2)
                        {
                            // 沒有資料就離開
                            if (!info.ContainsKey("B" + nums[i]))
                                break;
                            // 分數
                            gameInfo.HomeBoard.Add(info["B" + nums[i]]);
                            gameInfo.AwayBoard.Add(info["B" + nums[i + 1]]);
                        }
                        gameInfo.AwayPoint = info["AH"];
                        gameInfo.HomePoint = info["AG"];
                    }
                    #endregion
                    #region 比賽狀態
                    switch (info["AB"])
                    {
                        case "2":
                            gameInfo.GameStates = "S";
                            // 狀態
                            if (info.ContainsKey("AC") &&
                                (info["AC"] == "38" ||
                                 info["AC"] == "46"))
                            {
                                gameInfo.Status = "中場休息";
                            }
                            if (info.ContainsKey("BX"))
                            {
                                // 剩餘時間
                                gameInfo.Status = (playMinute - int.Parse(info["BX"])).ToString();
                            }

                            break;
                        case "3":
                            if (info.ContainsKey("AC"))
                            {
                                switch (info["AC"])
                                {
                                    case "4":
                                    case "5":
                                    case "36":
                                        gameInfo.GameStates = "P";
                                        gameInfo.Status = "中止";
                                        break;
                                    default:
                                        gameInfo.GameStates = "E";
                                        gameInfo.Status = "結束";
                                        break;
                                }
                            }
                            else
                            {
                                gameInfo.GameStates = "E";
                                gameInfo.Status = "結束";
                            }
                            break;
                    }
                    //最後修正只顯示最終比分的賽事狀態,有些結束賽事的ZF字段也為2,需要排除這種結束賽事
                    if (trackerText != null && info["AB"] != "3" && info["AC"] != "3")
                    {
                        gameInfo.TrackerText = trackerText;
                    }
                    #endregion
                    //if (gameInfo.GameStates == "S")
                    //{
                    //    int num = 0;
                    //    // 加時
                    //    if (gameInfo.Quarter == 4)
                    //    {
                    //        if (!string.IsNullOrEmpty(gameInfo.Status) &&
                    //            int.TryParse(gameInfo.Status, out num))
                    //        {
                    //            num = 20 - num;                             // 還原時間
                    //            gameInfo.Status = (5 - num).ToString();   // 經過時間
                    //        }
                    //    }
                    //}
                    // 加入
                    #region 排序
                    gameInfo.OrderBy = orderBy;
                    #endregion
                    gameInfo.Display = 1;
                    result[gameInfo.WebID] = gameInfo;
                }
                orderBy++;
            }
            // 傳回
            if (result.Count > 0)
            {
                DateTime maxGameTime = result.Values.Max(p => p.GameTime);//取最大开赛时间 作为比赛日期
                download.GameDate = maxGameTime.Date;
                List<BasicInfo> overDayGames = result.Values.Where(p => p.GameTime.Date < maxGameTime.Date).ToList();//比赛日期小于最大开赛时间的日期的为跨天赛事
                StringBuilder sb = new StringBuilder("OverDayGame:\r\n");
                overDayGames.ForEach(p =>
                {
                    p.OverDayGame = true;
                    sb.Append(p.ToString() + "\r\n");
                });
                if (overDayGames.Count > 0)
                {
                    this.Logs.GameInfo(sb.ToString());
                }
                PrintGame(result, download.GameDate.ToString(DATE_STRING_FORMAT), "DownGame",true);
            }
            return result;
        }