public static void parseATPSingle(string date, string[] tourTitle, string tourContent) { string fullContent = tourContent; int index = 0; while (index != -1) { int startIndex = tourContent.IndexOf("nowrap") + 45; tourContent = tourContent.Substring(startIndex, tourContent.Length - startIndex); int endIndex = tourContent.IndexOf("display: none;"); tourContent = tourContent.Substring(0, endIndex); Boolean isWritable = true; Boolean isPalyerCorrect = true; Boolean isDateCorrect = false; Boolean isScoreCorrect = true; int index2 = 0; int h = 0, m = 0; int scoreP1 = 0, scoreP2 = 0; int set1P1 = 0, set1P2 = 0, set2P1 = 0, set2P2 = 0, set3P1 = 0, set3P2 = 0; string playerNames = "", winner = ""; string isCancelled = "Cancelled"; int end1 = tourContent.IndexOf("</b><br>"); playerNames = tourContent.Substring(0, end1); string[] player = new string[3]; player = ClassParsePlayersName.parseName(playerNames); if (player[0] == "false") { isPalyerCorrect = false; } end1 += 9; tourContent = tourContent.Substring(end1, tourContent.Length - end1); string year = tourContent.Substring(6, 4); try { if (int.Parse(year) > 2000) { h = int.Parse(tourContent.Substring(11, 2)); m = int.Parse(tourContent.Substring(14, 2)); isDateCorrect = true; } } catch (Exception) { isDateCorrect = false; } if (!isDateCorrect) { if (year.IndexOf(".") == 0) { year = tourContent.Substring(7, 4); h = int.Parse(tourContent.Substring(12, 2)); m = int.Parse(tourContent.Substring(15, 2)); } else { MessageBox.Show("The date is not found!\nMessage:" + year); } } index2 = tourContent.IndexOf("valign=middle") + 17; string results = tourContent.Substring(index2, 30); if (results.Contains("Счет") || results.Contains("Score") || results.Contains("Есеп")) { isCancelled = "Null"; } else if (tourContent.Contains("отмен") || tourContent.Contains("завершен") || tourContent.Contains("0:0") || tourContent.Contains("0:1") || tourContent.Contains("1:0") || tourContent.Contains("1:1")) { isCancelled = "Cancelled"; } else { isCancelled = "Cancelled"; //MessageBox.Show("Results not found!\nMessage: " + tourContent + "\nMessage: " + fullContent); } if (isPalyerCorrect && isCancelled == "Null") { try { if (results.Contains("Score")) { results = results.Substring(1, results.Length - 1); } scoreP1 = int.Parse(results.Substring(6, 1)); scoreP2 = int.Parse(results.Substring(8, 1)); if (scoreP1 > scoreP2) { winner = "1"; } else if (scoreP2 > scoreP1) { winner = "2"; } else { isWritable = false; MessageBox.Show("Winners not found!\nMessage: " + tourContent); } if (scoreP1 + scoreP2 == 2) { set1P1 = int.Parse(results.Substring(11, 1)); set1P2 = int.Parse(results.Substring(13, 1)); set2P1 = int.Parse(results.Substring(15, 1)); set2P2 = int.Parse(results.Substring(17, 1)); } else if (scoreP1 + scoreP2 == 3) { set1P1 = int.Parse(results.Substring(11, 1)); set1P2 = int.Parse(results.Substring(13, 1)); set2P1 = int.Parse(results.Substring(15, 1)); set2P2 = int.Parse(results.Substring(17, 1)); try { set3P1 = int.Parse(results.Substring(19, 1)); set3P2 = int.Parse(results.Substring(21, 1)); } catch (Exception) { isScoreCorrect = false; } } else { isWritable = false; MessageBox.Show("Score not found!\nMessage: " + tourContent); } if (!isScoreCorrect) { if (scoreP1 > scoreP2) { set3P1 = int.Parse(results.Substring(19, 2)); set3P2 = int.Parse(results.Substring(22, 1)); } if (scoreP1 < scoreP2) { set3P1 = int.Parse(results.Substring(19, 1)); set3P2 = int.Parse(results.Substring(21, 2)); } } string hh = h.ToString(); if (h < 10) { hh = "0" + h.ToString(); } string mm = m.ToString(); if (m < 10) { mm = "0" + m.ToString(); } if (isWritable) { StreamWriter sw = new StreamWriter("dataPhase2/dataATPSingle.txt", true); sw.WriteLine(date + "," + hh + "," + mm + "," + tourTitle[1] + "," + tourTitle[2] + "," + tourTitle[3] + "," + tourTitle[4] + "," + tourTitle[5] + "," + tourTitle[6] + "," + player[1] + "," + winner + "," + player[2] + "," + scoreP1 + "," + scoreP2 + "," + set1P1 + "," + set1P2 + "," + set2P1 + "," + set2P2 + "," + set3P1 + "," + set3P2); sw.Close(); } } catch (Exception) { MessageBox.Show("Something wrong with scores! Message: " + results); } } index = tourContent.IndexOf("nowrap"); } }
public static void parseATPSinge(string url, string[] title) { string sourceCode = ClassHttpWebRequest.source(url); for (int i = 0; i != -1; i = sourceCode.IndexOf("(+")) { string coefficients = ""; for (int a = 0; a < title.Length; a++) { coefficients += title[a] + ","; } int dateStartIndex = sourceCode.IndexOf("(+") + 16; sourceCode = sourceCode.Substring(dateStartIndex, sourceCode.Length - dateStartIndex); int nameEndIndex = sourceCode.IndexOf("</a></span></b></font></td>"); string eachDateName = sourceCode.Substring(0, nameEndIndex); int nameStartIndex = eachDateName.LastIndexOf(">"); string playerNames = eachDateName.Substring(nameStartIndex + 1, eachDateName.Length - nameStartIndex - 1); Boolean isPalyerSingle = true; Boolean isWritable = true; string[] player = new string[3]; player = ClassParsePlayersName.parseName(playerNames); if (player[0] == "false") { isPalyerSingle = false; isWritable = false; continue; } coefficients += player[1] + ","; coefficients += player[2] + ","; int d, m, y, h, n; try { d = int.Parse(eachDateName.Substring(0, 2)); m = int.Parse(eachDateName.Substring(3, 2)); y = int.Parse(eachDateName.Substring(6, 4)); h = int.Parse(eachDateName.Substring(11, 2)); n = int.Parse(eachDateName.Substring(14, 2)); } catch (Exception) { isWritable = false; continue; } string date, time, day, month, year, hour, min; if (d < 10) { day = "0" + d; } else { day = d.ToString(); } if (m < 10) { month = "0" + m; } else { month = m.ToString(); } year = y.ToString(); if (h < 10) { hour = "0" + h; } else { hour = h.ToString(); } if (n < 10) { min = "0" + n; } else { min = n.ToString(); } date = year + month + day; time = hour + ":" + min; coefficients = time + "," + coefficients; coefficients = date + "," + coefficients; int koefsStartIndex = sourceCode.IndexOf("П1") - 64; string eachGameKoefs = sourceCode.Substring(koefsStartIndex, sourceCode.Length - koefsStartIndex); eachGameKoefs = eachGameKoefs.Substring(0, eachGameKoefs.IndexOf("Тот(") + 800); string koefName = ""; int koefTotalOverStartIndex = eachGameKoefs.LastIndexOf("googleStatKef") + 15; string koefTotalOver = eachGameKoefs.Substring(koefTotalOverStartIndex, eachGameKoefs.Length - koefTotalOverStartIndex); int koefTotalOverEndIndex = koefTotalOver.IndexOf("</span>"); koefTotalOver = koefTotalOver.Substring(0, koefTotalOverEndIndex); int coefCounter = 0; for (int a = 0; a != -1; a = eachGameKoefs.IndexOf("googleStatIssueName")) { try { int koefNameStartIndex = eachGameKoefs.IndexOf("googleStatIssueName") + 21; eachGameKoefs = eachGameKoefs.Substring(koefNameStartIndex, eachGameKoefs.Length - koefNameStartIndex); int koefNameEndIndex = eachGameKoefs.IndexOf("googleStatKef") + 40; string eachNameKoef = eachGameKoefs.Substring(0, eachGameKoefs.Length - koefNameEndIndex); int kNameEndIndex = eachNameKoef.IndexOf("</span>"); koefName = eachNameKoef.Substring(0, kNameEndIndex); int koefStartIndex = eachNameKoef.IndexOf("googleStatKef") + 15; string koef = eachNameKoef.Substring(koefStartIndex, eachNameKoef.Length - koefStartIndex); int koefEndIndex = koef.IndexOf("</span>"); koef = koef.Substring(0, koefEndIndex); if (koefName.Contains("Тот(")) { koefName += ":U"; } koefName = ClassParseCoefficientName.parseCoefficientName(koefName); coefficients += koefName + "=" + koef + ","; } catch (Exception) { coefficients = ""; continue; } coefCounter++; } if (coefCounter != 9) { coefficients = ""; continue; } koefName = koefName.Substring(0, koefName.Length - 1); koefName += "O"; coefficients += koefName + "=" + koefTotalOver + "\n"; if (coefficients.Contains(")=") && coefficients.Contains("):U=")) { ClassFileManagement.writeToFile("dataPhase3/coefficientUpcomingATPSingle.txt", coefficients, true); isWritable = isCoefficientUnique(date, player[1], player[2]); if (isWritable) { ClassFileManagement.writeToFile("dataPhase3/coefficientATPSingle.txt", coefficients, true); } } else { continue; } } }