private List <RetrievedOdds> FilterOddsList(List <RetrievedOdds> oddsList) { List <RetrievedOdds> tempOddsList = new List <RetrievedOdds>(); foreach (RetrievedOdds odds in oddsList) { if (odds.isProfitable) { string source = odds.source; string URL = odds.URL; double tempStake = stake; SafeInvokeFormControl(stakeControl, () => { tempStake = (double)stakeControl.Value; }); double tempProfitPC = minProfit; SafeInvokeFormControl(minProfitControl, () => { tempProfitPC = (double)minProfitControl.Value; }); int tempHours = maxHrs; SafeInvokeFormControl(maxHoursControl, () => { tempHours = (int)maxHoursControl.Value; }); int tempBets = maxUniqueBets; SafeInvokeFormControl(maxUniqueBetsControl, () => { tempBets = (int)stakeControl.Value; }); bool tempInPlay = includeInPlay; SafeInvokeFormControl(inPlayControl, () => { tempInPlay = inPlayControl.Checked; }); RetrievedOdds tempOdds = new RetrievedOdds(URL, source, enabledBookmakers.ToList(), tempStake); bool include = true; if (!includeInPlay && tempOdds.inPlay) { include = false; } if (tempOdds.timeToEvent.TotalHours > maxHrs) { include = false; } if (tempOdds.results.Count > maxUniqueBets) { include = false; } if (tempOdds.profitPercentage < minProfit) { include = false; } if (include) { tempOddsList.Add(tempOdds); } } } return(tempOddsList); }
private void PopulateEventLabels(RetrievedOdds odds) { selectedOdds = odds; eventRefreshButton.Enabled = true; string sport = odds.sport; string sportBracket = odds.sportBracket; string name = odds.eventName; string type = odds.betType; string time = odds.eventTime.ToString(dateFormat); string profit = string.Format("{0:0.00}", odds.profit); string oddsCheckerlink = odds.URL; eventSportLabel.Text = sport + ", " + sportBracket; eventNameTypeLabel.Text = name + ", " + type; eventTimeLabel.Text = time; eventMinProfitLabel.Text = "Minimum Profit: " + profit; oddsCheckerLinkLabel.Enabled = true; oddsCheckerLinkLabel.Links[0].LinkData = oddsCheckerlink; ClearResultLinks(); int i = 1; foreach (Result res in odds.results) { string text = string.Format("\nPut {0:0.00} on {1} at {4} to return {2:0.00} with {3}.", res.bet, res.name, res.betReturn, res.bookmaker.Name, res.odds); string URL = "https://www.google.com/search?q="; URL += res.bookmaker.Name + "+" + odds.eventName + "+" + odds.betType; LinkLabel linkLabel = new LinkLabel(); int horizontalPosition = oddsCheckerLinkLabel.Location.X; int verticalPosition = oddsCheckerLinkLabel.Location.Y + (linkVerticalSep * i); i++; linkLabel.Location = new System.Drawing.Point(horizontalPosition, verticalPosition); linkLabel.Size = new System.Drawing.Size(224, 16); linkLabel.AutoSize = true; linkLabel.LinkBehavior = LinkBehavior.NeverUnderline; linkLabel.Text = text; linkLabel.LinkArea = new LinkArea(0, text.Length); linkLabel.Links[0].LinkData = URL; linkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkClicked); resultLinks.Add(linkLabel); Controls.Add(linkLabel); } }
private void eventRefreshButton_Click(object sender, EventArgs e) { eventRefreshButton.Enabled = false; //HtmlAgilityPack.HtmlDocument doc; //doc = LoadSource(GetPage(selectedOdds.URL)); string source = linkChecker.GetPage(selectedOdds.URL); if (source == null) { source = selectedOdds.source; PopulateEventLabels(selectedOdds); } else { RetrievedOdds tempOdds = new RetrievedOdds(selectedOdds.URL, source, enabledBookmakers, stake); filteredOddsList[selectedOddsIndex] = tempOdds; PopulateEventLabels(tempOdds); UpdateOddsList(oddsList); } eventRefreshButton.Enabled = true; }
private void GetUniqueLinks(string url) { int maxRetries = 3; int attempts = 0; string source = ""; while (source == "" && attempts < maxRetries) { source = GetPage(url); attempts++; } HtmlDocument doc = LoadSource(source); //if (doc == null) return; if (doc.DocumentNode.SelectNodes("//a[@href]") != null) { foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]")) { HtmlAttribute att = link.Attributes["href"]; string linkString = att.Value; if (linkString.StartsWith("/")) { linkString = baseURL + linkString; } if (!linksList.Contains(linkString)) { bool excluded = false; bool included = false; foreach (string exclusion in exclusions) { if (linkString.Contains(exclusion)) { excluded = true; } } foreach (string inclusion in inclusions) { if (linkString.Contains(inclusion)) { included = true; } } if (linkString.StartsWith(baseURL) && !excluded && included) { linksList.Add(linkString); int index = linksList.Count; } } } } // TODO: Work out exception try { RetrievedOdds odds = new RetrievedOdds(url, source, bookMakers, stake); List <string> output = new List <string>(); oddsList.Add(odds); } catch (Exception e) { string message = string.Format("Exception retriving odds for URL: {0}\nException details: {1}", url, e.ToString()); System.Windows.Forms.MessageBox.Show(message); } }