private Dictionary<string, BasicInfo> GetTennisData(TennisDownload download) { string dataSource = download.Data; // dataSource = Read(@"D:\TFS_Code\TFSmain_SP_TFS_CODE\AP\Follow\game.txt"); // 沒有資料就離開 if (string.IsNullOrEmpty(dataSource)) return null; Dictionary<string, BasicInfo> result = new Dictionary<string, BasicInfo>(); BasicInfo gameInfo = null; string[] all = dataSource.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 gameState = 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); // 判斷並記錄 if (txt.Length == 2) info[txt[0]] = txt[1]; } #endregion #region 第一筆是聯盟 if (gameIndex == 0) { allianceName = info["ZA"]; if (info["ZF"] == "2") { gameState = "只顯示</br>最終比分"; } 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"], true); #region 設定 gameInfo.OverDayGame = false; string runsA = ""; string runsB = ""; gameInfo.Home = info["AE"].Replace("GOAL", "").Replace("SET", ""); gameInfo.Away = info["AF"].Replace("GOAL", "").Replace("SET", ""); gameInfo.HomePoint = (info.ContainsKey("AG")) ? (info["AG"]) : ("-"); gameInfo.AwayPoint = (info.ContainsKey("AH")) ? (info["AH"]) : ("-"); gameInfo.WN = 0; gameInfo.PR = 0; gameInfo.TrackerText = "只有最終結果"; gameInfo.GameStates = ""; #endregion #region 分數 string[] nums = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; for (int i = 0; i < nums.Length; i += 2) { runsA += "," + ((info.ContainsKey("B" + nums[i])) ? (info["B" + nums[i]]) : ("")); runsA += ((info.ContainsKey("D" + nums[i])) ? (string.Format("<sup>{0}</sup>", info["D" + nums[i]])) : ("")); runsB += "," + ((info.ContainsKey("B" + nums[i + 1])) ? (info["B" + nums[i + 1]]) : ("")); runsB += ((info.ContainsKey("D" + nums[i + 1])) ? (string.Format("<sup>{0}</sup>", info["D" + nums[i + 1]])) : ("")); // 盤數 if (info.ContainsKey("B" + nums[i])) { gameInfo.GameStates = (i / 2 + 1).ToString(); } } // 球數 runsA += "," + ((info.ContainsKey("WA") && info["AB"] == "2") ? (info["WA"]) : ("")); runsA = runsA.Substring(1); runsB += "," + ((info.ContainsKey("WB") && info["AB"] == "2") ? (info["WB"]) : ("")); runsB = runsB.Substring(1); #endregion #region LIVE if ((info.ContainsKey("AN") && info["AN"] == "y") || (info.ContainsKey("AI") && info["AI"] == "y")) { gameInfo.TrackerText = "即時更新"; } #endregion #region 比賽狀態 switch (info["AB"]) { case "1": gameInfo.GameStates = "未開賽"; break; case "2": gameInfo.GameStates = string.Format("第 {0} 盤", gameInfo.GameStates); if (info.ContainsKey("WC")) gameInfo.PR = Convert.ToInt32(info["WC"]); break; case "3": switch (info["AC"]) { case "5": gameInfo.GameStates = "取消"; break; case "8": gameInfo.GameStates = "結束</br>(比賽中棄權)"; break; case "9": gameInfo.GameStates = "不戰而勝"; break; case "36": gameInfo.GameStates = "中斷"; break; default: gameInfo.GameStates = "結束"; break; } #region 輸贏 int teamA = 0; int teamB = 0; if (int.TryParse(gameInfo.HomePoint.ToString(), out teamA) && int.TryParse(gameInfo.AwayPoint.ToString(), out teamB)) { if (teamA > teamB) gameInfo.WN = 1; if (teamA < teamB) gameInfo.WN = 2; } #endregion break; } gameInfo.AllianceName = allianceName; gameInfo.HomeBoard = runsA.Split(',').ToList(); gameInfo.AwayBoard = runsB.Split(',').ToList(); //最後修正只顯示最終比分的賽事狀態,有些結束賽事的ZF字段也為2,需要排除這種結束賽事 if (gameState != null && info["AB"] !="2" && info["AB"] != "3" && info["AC"] != "3") { gameInfo.GameStates = gameState; } #endregion #region 排序 gameInfo.OrderBy = orderBy; #endregion // 加入 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; }
public Tennis(DateTime today) : base(ESport.Tennis) { // Tennis 讀取翻譯表/聯盟表 this.LoadNameControlAndAlliance(); this.Logs = new LogFile(ESport.Tennis);//設定log type if (string.IsNullOrWhiteSpace(this.sWebUrl)) { this.sWebUrl = "http://d.flashscore.com/x/feed/f_2_0_8_en-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_2_-1_8_en-asia_1"; } if (string.IsNullOrWhiteSpace(this.sWebUrl3)) { this.sWebUrl3 = "http://d.flashscore.com/x/feed/f_2_"; } // 設定 this.AllianceID = 0; this.GameType = "TN"; this.GameDate = GetUtcTw(today).Date; // 只取日期 this.DownHome = new TennisDownload(this.Sport, this.GameDate, this.sWebUrl, "f_2_0_8_en-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.1433729535.1; __utmb=175935605.6.10.1433729535; __utmc=175935605; __utmz=175935605.1433729535.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __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<TennisDownload>(); this.DownReal.Add(new TennisDownload(this.Sport, this.GameDate.AddDays(startIndex), this.sWebUrl2, "f_2_-1_8_en-asia_1")); // 往後 7 天 for (int i = 1; i <= endIndex; i++) { this.DownReal.Add(new TennisDownload(this.Sport, this.GameDate.AddDays(i), this.sWebUrl3 + i + "_8_en-asia_1", "f_2_" + i + "_8_en-asia_1")); } #region 從資料庫中取得舊資料 GetOldGames(); #endregion 從資料庫中取得舊資料 }